diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 8eb65102..024b92fb 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -66,7 +66,7 @@ public class CSVFormat implements Serializable { public static final CSVFormat DEFAULT = PRISTINE .withDelimiter(COMMA) - .withEncapsulator(DOUBLE_QUOTE) + .withQuoteChar(DOUBLE_QUOTE) .withIgnoreEmptyLines(true) .withLineSeparator(CRLF); @@ -82,7 +82,7 @@ public class CSVFormat implements Serializable { public static final CSVFormat RFC4180 = PRISTINE .withDelimiter(COMMA) - .withEncapsulator(DOUBLE_QUOTE) + .withQuoteChar(DOUBLE_QUOTE) .withLineSeparator(CRLF); /** @@ -98,14 +98,14 @@ public class CSVFormat implements Serializable { public static final CSVFormat EXCEL = PRISTINE .withDelimiter(COMMA) - .withEncapsulator(DOUBLE_QUOTE) + .withQuoteChar(DOUBLE_QUOTE) .withLineSeparator(CRLF); /** Tab-delimited format, with quote; leading and trailing spaces ignored. */ public static final CSVFormat TDF = PRISTINE .withDelimiter(TAB) - .withEncapsulator(DOUBLE_QUOTE) + .withQuoteChar(DOUBLE_QUOTE) .withIgnoreSurroundingSpaces(true) .withIgnoreEmptyLines(true) .withLineSeparator(CRLF); @@ -258,8 +258,8 @@ public class CSVFormat implements Serializable { * @throws IllegalArgumentException * thrown if the specified character is a line break */ - public CSVFormat withEncapsulator(final char encapsulator) { - return withEncapsulator(Character.valueOf(encapsulator)); + public CSVFormat withQuoteChar(final char quoteChar) { + return withQuoteChar(Character.valueOf(quoteChar)); } /** @@ -271,11 +271,11 @@ public class CSVFormat implements Serializable { * @throws IllegalArgumentException * thrown if the specified character is a line break */ - public CSVFormat withEncapsulator(final Character encapsulator) { - if (isLineBreak(encapsulator)) { + public CSVFormat withQuoteChar(final Character quoteChar) { + if (isLineBreak(quoteChar)) { throw new IllegalArgumentException("The quoteChar cannot be a line break"); } - return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape, + return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape, ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header); } diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java index c726e222..788dba14 100644 --- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java @@ -88,7 +88,7 @@ public class CSVFileParserTest { assertTrue(testName+" require 1 param", split.length >= 1); // first line starts with csv data file name final BufferedReader csvFile = new BufferedReader(new FileReader(new File(BASE, split[0]))); - CSVFormat fmt = CSVFormat.PRISTINE.withDelimiter(',').withEncapsulator('"'); + CSVFormat fmt = CSVFormat.PRISTINE.withDelimiter(',').withQuoteChar('"'); boolean checkComments = false; for(int i=1; i < split.length; i++) { final String option = split[i]; diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index df31a75d..2e4fea10 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -38,7 +38,7 @@ public class CSVFormatTest { final CSVFormat format = new CSVFormat('!', '!', Quote.MINIMAL, '!', '!', true, true, CRLF, null); format.withDelimiter('?'); - format.withEncapsulator('?'); + format.withQuoteChar('?'); format.withCommentStart('?'); format.withLineSeparator("?"); format.withEscape('?'); @@ -63,7 +63,7 @@ public class CSVFormatTest { final CSVFormat format = new CSVFormat('!', '!', null, '!', '!', true, true, CRLF, null); assertEquals('?', format.withDelimiter('?').getDelimiter()); - assertEquals('?', format.withEncapsulator('?').getQuoteChar().charValue()); + assertEquals('?', format.withQuoteChar('?').getQuoteChar().charValue()); assertEquals('?', format.withCommentStart('?').getCommentStart().charValue()); assertEquals("?", format.withLineSeparator("?").getLineSeparator()); assertEquals('?', format.withEscape('?').getEscape().charValue()); @@ -102,7 +102,7 @@ public class CSVFormatTest { } try { - format.withEncapsulator('\n'); + format.withQuoteChar('\n'); fail(); } catch (final IllegalArgumentException e) { // expected @@ -130,13 +130,13 @@ public class CSVFormatTest { } try { - format.withEncapsulator('!').withCommentStart('!').validate(); + format.withQuoteChar('!').withCommentStart('!').validate(); fail(); } catch (final IllegalStateException e) { // expected } - format.withEncapsulator(null).withCommentStart(null).validate(); + format.withQuoteChar(null).withCommentStart(null).validate(); try { format.withEscape('!').withCommentStart('!').validate(); @@ -149,7 +149,7 @@ public class CSVFormatTest { try { - format.withEncapsulator('!').withDelimiter('!').validate(); + format.withQuoteChar('!').withDelimiter('!').validate(); fail(); } catch (final IllegalStateException e) { // expected diff --git a/src/test/java/org/apache/commons/csv/CSVLexerTest.java b/src/test/java/org/apache/commons/csv/CSVLexerTest.java index ef0dbe38..09c04f1a 100644 --- a/src/test/java/org/apache/commons/csv/CSVLexerTest.java +++ b/src/test/java/org/apache/commons/csv/CSVLexerTest.java @@ -259,7 +259,7 @@ public class CSVLexerTest { * ;; */ final String code = "a;'b and '' more\n'\n!comment;;;;\n;;"; - final CSVFormat format = CSVFormat.DEFAULT.withDelimiter(';').withEncapsulator('\'').withCommentStart('!'); + final CSVFormat format = CSVFormat.DEFAULT.withDelimiter(';').withQuoteChar('\'').withCommentStart('!'); final Lexer parser = getLexer(code, format); assertTokenEquals(TOKEN, "a", parser.nextToken(new Token())); assertTokenEquals(EORECORD, "b and ' more\n", parser.nextToken(new Token())); diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index de05d128..3d75da39 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -309,7 +309,7 @@ public class CSVParserTest { }; - final CSVFormat format = CSVFormat.PRISTINE.withDelimiter(',').withEncapsulator('\'').withEscape('/') + final CSVFormat format = CSVFormat.PRISTINE.withDelimiter(',').withQuoteChar('\'').withEscape('/') .withIgnoreEmptyLines(true).withLineSeparator(CRLF); final CSVParser parser = new CSVParser(code, format);