Skip to content

Commit bb54feb

Browse files
committed
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
1 parent f51f898 commit bb54feb

2 files changed

Lines changed: 6 additions & 18 deletions

File tree

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,9 @@ public Quote getQuotePolicy() {
557557
}
558558

559559
/**
560-
* Returns the line separator delimiting output records.
560+
* Returns the record separator delimiting output records.
561561
*
562-
* @return the line separator
562+
* @return the record separator
563563
*/
564564
public String getRecordSeparator() {
565565
return recordSeparator;
@@ -738,13 +738,6 @@ private void validate() throws IllegalArgumentException {
738738
if (escape == null && quotePolicy == Quote.NONE) {
739739
throw new IllegalArgumentException("No quotes mode set but no escape character is set");
740740
}
741-
742-
if(recordSeparator != null &&
743-
!(CRLF.equals(recordSeparator) ||
744-
String.valueOf(CR).equals(recordSeparator) ||
745-
String.valueOf(LF).equals(recordSeparator))) {
746-
throw new IllegalArgumentException("Record separator can only by CR, LF or CRLF");
747-
}
748741
}
749742

750743
/**
@@ -965,14 +958,13 @@ public CSVFormat withQuotePolicy(final Quote quotePolicy) {
965958
/**
966959
* Sets the record separator of the format to the specified character.
967960
*
968-
* <p><strong>Note:</strong> Currently only CR and LF are supported.</p>
961+
* <p><strong>Note:</strong> This setting is only used during printing and does not affect parsing. Parsing currently
962+
* only works for inputs with '\n', '\r' and "\r\n"</p>
969963
*
970964
* @param recordSeparator
971965
* the record separator to use for output.
972966
*
973967
* @return A new CSVFormat that is equal to this but with the the specified output record separator
974-
* @throws IllegalArgumentException
975-
* if recordSeparator is neither CR nor LF
976968
*/
977969
public CSVFormat withRecordSeparator(final char recordSeparator) {
978970
return withRecordSeparator(String.valueOf(recordSeparator));
@@ -981,7 +973,8 @@ public CSVFormat withRecordSeparator(final char recordSeparator) {
981973
/**
982974
* Sets the record separator of the format to the specified String.
983975
*
984-
* <p><strong>Note:</strong> Currently only CR, LF and CRLF are supported.</p>
976+
* <p><strong>Note:</strong> This setting is only used during printing and does not affect parsing. Parsing currently
977+
* only works for inputs with '\n', '\r' and "\r\n"</p>
985978
*
986979
* @param recordSeparator
987980
* the record separator to use for output.

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,4 @@ public void testWithRecordSeparatorCRLF() throws Exception {
426426
final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator(CRLF);
427427
assertEquals(CRLF, formatWithRecordSeparator.getRecordSeparator());
428428
}
429-
430-
@Test(expected = IllegalArgumentException.class)
431-
public void testWithRecordSeparatorIllegal() throws Exception {
432-
CSVFormat.DEFAULT.withRecordSeparator('!');
433-
}
434429
}

0 commit comments

Comments
 (0)