Rename "encapsulator" to "quoteChar" so we have quoteChar and quotePolicy. Encapsulator makes me want to ask "encapsulate what"? fieldEncapsulator would be better but so verbose, quoteChar feels more to the point to me and provides symmetry with quotePolicy.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1398010 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2012-10-14 05:00:19 +00:00
parent 6e57364216
commit ecea0c3599
5 changed files with 18 additions and 18 deletions

View File

@ -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);
}

View File

@ -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];

View File

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

View File

@ -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()));

View File

@ -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);