Clearify handling of record separators and remove senseless validation

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1610492 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benedikt Ritter 2014-07-14 19:30:37 +00:00
parent f51f89828d
commit bb54feb7cd
2 changed files with 6 additions and 18 deletions

View File

@ -557,9 +557,9 @@ public final class CSVFormat implements Serializable {
}
/**
* Returns the line separator delimiting output records.
* Returns the record separator delimiting output records.
*
* @return the line separator
* @return the record separator
*/
public String getRecordSeparator() {
return recordSeparator;
@ -738,13 +738,6 @@ public final class CSVFormat implements Serializable {
if (escape == null && quotePolicy == Quote.NONE) {
throw new IllegalArgumentException("No quotes mode set but no escape character is set");
}
if(recordSeparator != null &&
!(CRLF.equals(recordSeparator) ||
String.valueOf(CR).equals(recordSeparator) ||
String.valueOf(LF).equals(recordSeparator))) {
throw new IllegalArgumentException("Record separator can only by CR, LF or CRLF");
}
}
/**
@ -965,14 +958,13 @@ public final class CSVFormat implements Serializable {
/**
* Sets the record separator of the format to the specified character.
*
* <p><strong>Note:</strong> Currently only CR and LF are supported.</p>
* <p><strong>Note:</strong> This setting is only used during printing and does not affect parsing. Parsing currently
* only works for inputs with '\n', '\r' and "\r\n"</p>
*
* @param recordSeparator
* the record separator to use for output.
*
* @return A new CSVFormat that is equal to this but with the the specified output record separator
* @throws IllegalArgumentException
* if recordSeparator is neither CR nor LF
*/
public CSVFormat withRecordSeparator(final char recordSeparator) {
return withRecordSeparator(String.valueOf(recordSeparator));
@ -981,7 +973,8 @@ public final class CSVFormat implements Serializable {
/**
* Sets the record separator of the format to the specified String.
*
* <p><strong>Note:</strong> Currently only CR, LF and CRLF are supported.</p>
* <p><strong>Note:</strong> This setting is only used during printing and does not affect parsing. Parsing currently
* only works for inputs with '\n', '\r' and "\r\n"</p>
*
* @param recordSeparator
* the record separator to use for output.

View File

@ -426,9 +426,4 @@ public class CSVFormatTest {
final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator(CRLF);
assertEquals(CRLF, formatWithRecordSeparator.getRecordSeparator());
}
@Test(expected = IllegalArgumentException.class)
public void testWithRecordSeparatorIllegal() throws Exception {
CSVFormat.DEFAULT.withRecordSeparator('!');
}
}