From bb54feb7cde6445d1e85fb9eb028a38823bbf0a7 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Mon, 14 Jul 2014 19:30:37 +0000 Subject: [PATCH] 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 --- .../org/apache/commons/csv/CSVFormat.java | 19 ++++++------------- .../org/apache/commons/csv/CSVFormatTest.java | 5 ----- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 191d263a..811a1629 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -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. * - *

Note: Currently only CR and LF are supported.

+ *

Note: This setting is only used during printing and does not affect parsing. Parsing currently + * only works for inputs with '\n', '\r' and "\r\n"

* * @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. * - *

Note: Currently only CR, LF and CRLF are supported.

+ *

Note: This setting is only used during printing and does not affect parsing. Parsing currently + * only works for inputs with '\n', '\r' and "\r\n"

* * @param recordSeparator * the record separator to use for output. diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index fe2fc30c..28c7c9c3 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -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('!'); - } }