You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/10/16 00:50:00 UTC
svn commit: r1398556 - in /commons/proper/csv/trunk/src:
main/java/org/apache/commons/csv/CSVFormat.java
test/java/org/apache/commons/csv/CSVFormatTest.java
Author: sebb
Date: Mon Oct 15 22:50:00 2012
New Revision: 1398556
URL: http://svn.apache.org/viewvc?rev=1398556&view=rev
Log:
Add ctor to create simplest possible CSV parser
Does not make sense to allow delim = EOL in ctor but disable it in withDelimiter()
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java?rev=1398556&r1=1398555&r2=1398556&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java Mon Oct 15 22:50:00 2012
@@ -127,10 +127,21 @@ public class CSVFormat implements Serial
.withLineSeparator(LF);
/**
+ * Creates a basic CSV format.
+ *
+ * @param delimiter
+ * the char used for value separation, must not be a line break character
+ * @throws IllegalArgumentException if the delimiter is a line break character
+ */
+ public CSVFormat(char delimiter){
+ this(delimiter, null, null, null, null, false, false, null, null);
+ }
+
+ /**
* Creates a customized CSV format.
*
* @param delimiter
- * the char used for value separation
+ * the char used for value separation, must not be a line break character
* @param quoteChar
* the char used as value encapsulation marker
* @param quotePolicy
@@ -147,10 +158,14 @@ public class CSVFormat implements Serial
* the line separator to use for output
* @param header
* the header
+ * @throws IllegalArgumentException if the delimiter is a line break character
*/
public CSVFormat(final char delimiter, final Character quoteChar, final Quote quotePolicy, final Character commentStart, final Character escape, final
boolean ignoreSurroundingSpaces, final boolean ignoreEmptyLines, final String lineSeparator,
final String[] header) {
+ if (isLineBreak(delimiter)) {
+ throw new IllegalArgumentException("The delimiter cannot be a line break");
+ }
this.delimiter = delimiter;
this.quoteChar = quoteChar;
this.quotePolicy = quotePolicy;
@@ -238,9 +253,6 @@ public class CSVFormat implements Serial
* thrown if the specified character is a line break
*/
public CSVFormat withDelimiter(final char delimiter) {
- if (isLineBreak(delimiter)) {
- throw new IllegalArgumentException("The delimiter cannot be a line break");
- }
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
}
Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java?rev=1398556&r1=1398555&r2=1398556&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java Mon Oct 15 22:50:00 2012
@@ -89,6 +89,20 @@ public class CSVFormatTest {
@Test
public void testValidation() {
+ try {
+ new CSVFormat('\n');
+ fail();
+ } catch (final IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ new CSVFormat('\r');
+ fail();
+ } catch (final IllegalArgumentException e) {
+ // expected
+ }
+
final CSVFormat format = CSVFormat.DEFAULT;
try {