Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit 6e57364

Browse files
committed
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@1398009 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0030e1a commit 6e57364

5 files changed

Lines changed: 41 additions & 41 deletions

File tree

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ public class CSVFormat implements Serializable {
4040
private static final long serialVersionUID = 1L;
4141

4242
private final char delimiter;
43-
private final Character encapsulator;
43+
private final Character quoteChar;
44+
private final Quote quotePolicy;
4445
private final Character commentStart;
4546
private final Character escape;
4647
private final boolean ignoreSurroundingSpaces; // Should leading/trailing spaces be ignored around values?
4748
private final boolean ignoreEmptyLines;
4849
private final String lineSeparator; // for outputs
4950
private final String[] header;
50-
private final Quote quotePolicy;
5151

5252
/**
5353
* Starting format; used for creating other formats.
@@ -129,7 +129,7 @@ public class CSVFormat implements Serializable {
129129
*
130130
* @param delimiter
131131
* the char used for value separation
132-
* @param encapsulator
132+
* @param quoteChar
133133
* the char used as value encapsulation marker
134134
* @param quotePolicy
135135
* the quote policy
@@ -150,7 +150,7 @@ public CSVFormat(final char delimiter, final Character encapsulator, final Quote
150150
boolean ignoreSurroundingSpaces, final boolean ignoreEmptyLines, final String lineSeparator,
151151
final String[] header) {
152152
this.delimiter = delimiter;
153-
this.encapsulator = encapsulator;
153+
this.quoteChar = encapsulator;
154154
this.quotePolicy = quotePolicy;
155155
this.commentStart = commentStart;
156156
this.escape = escape;
@@ -178,8 +178,8 @@ private static boolean isLineBreak(final Character c) {
178178
* @throws IllegalStateException
179179
*/
180180
void validate() throws IllegalStateException {
181-
if (encapsulator != null && delimiter == encapsulator) {
182-
throw new IllegalStateException("The encapsulator character and the delimiter cannot be the same ('" + encapsulator + "')");
181+
if (quoteChar != null && delimiter == quoteChar) {
182+
throw new IllegalStateException("The quoteChar character and the delimiter cannot be the same ('" + quoteChar + "')");
183183
}
184184

185185
if (escape != null && delimiter == escape) {
@@ -191,8 +191,8 @@ void validate() throws IllegalStateException {
191191
"')");
192192
}
193193

194-
if (encapsulator != null && encapsulator == commentStart) {
195-
throw new IllegalStateException("The comment start character and the encapsulator cannot be the same ('" + commentStart +
194+
if (quoteChar != null && quoteChar == commentStart) {
195+
throw new IllegalStateException("The comment start character and the quoteChar cannot be the same ('" + commentStart +
196196
"')");
197197
}
198198

@@ -236,25 +236,25 @@ public CSVFormat withDelimiter(final Character delimiter) {
236236
if (isLineBreak(delimiter)) {
237237
throw new IllegalArgumentException("The delimiter cannot be a line break");
238238
}
239-
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
239+
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
240240
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
241241
}
242242

243243
/**
244244
* Returns the character used to encapsulate values containing special characters.
245245
*
246-
* @return the encapsulator character
246+
* @return the quoteChar character
247247
*/
248-
public Character getEncapsulator() {
249-
return encapsulator;
248+
public Character getQuoteChar() {
249+
return quoteChar;
250250
}
251251

252252
/**
253-
* Returns a copy of this format using the specified encapsulator character.
253+
* Returns a copy of this format using the specified quoteChar character.
254254
*
255-
* @param encapsulator
256-
* the encapsulator character
257-
* @return A copy of this format using the specified encapsulator character
255+
* @param quoteChar
256+
* the quoteChar character
257+
* @return A copy of this format using the specified quoteChar character
258258
* @throws IllegalArgumentException
259259
* thrown if the specified character is a line break
260260
*/
@@ -263,29 +263,29 @@ public CSVFormat withEncapsulator(final char encapsulator) {
263263
}
264264

265265
/**
266-
* Returns a copy of this format using the specified encapsulator character.
266+
* Returns a copy of this format using the specified quoteChar character.
267267
*
268-
* @param encapsulator
269-
* the encapsulator character
270-
* @return A copy of this format using the specified encapsulator character
268+
* @param quoteChar
269+
* the quoteChar character
270+
* @return A copy of this format using the specified quoteChar character
271271
* @throws IllegalArgumentException
272272
* thrown if the specified character is a line break
273273
*/
274274
public CSVFormat withEncapsulator(final Character encapsulator) {
275275
if (isLineBreak(encapsulator)) {
276-
throw new IllegalArgumentException("The encapsulator cannot be a line break");
276+
throw new IllegalArgumentException("The quoteChar cannot be a line break");
277277
}
278278
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
279279
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
280280
}
281281

282282
/**
283-
* Returns whether an encapsulator has been defined.
283+
* Returns whether an quoteChar has been defined.
284284
*
285-
* @return {@code true} if an encapsulator is defined
285+
* @return {@code true} if an quoteChar is defined
286286
*/
287287
public boolean isEncapsulating() {
288-
return encapsulator != null;
288+
return quoteChar != null;
289289
}
290290

291291
/**
@@ -327,7 +327,7 @@ public CSVFormat withCommentStart(final Character commentStart) {
327327
if (isLineBreak(commentStart)) {
328328
throw new IllegalArgumentException("The comment start character cannot be a line break");
329329
}
330-
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
330+
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
331331
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
332332
}
333333

@@ -377,7 +377,7 @@ public CSVFormat withEscape(final Character escape) {
377377
if (isLineBreak(escape)) {
378378
throw new IllegalArgumentException("The escape character cannot be a line break");
379379
}
380-
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
380+
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
381381
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
382382
}
383383

@@ -409,7 +409,7 @@ public boolean getIgnoreSurroundingSpaces() {
409409
* @return A copy of this format with the specified trimming behavior.
410410
*/
411411
public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpaces) {
412-
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
412+
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
413413
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
414414
}
415415

@@ -432,7 +432,7 @@ public boolean getIgnoreEmptyLines() {
432432
* @return A copy of this format with the specified empty line skipping behavior.
433433
*/
434434
public CSVFormat withIgnoreEmptyLines(final boolean ignoreEmptyLines) {
435-
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
435+
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
436436
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
437437
}
438438

@@ -454,7 +454,7 @@ public String getLineSeparator() {
454454
* @return A copy of this format using the specified output line separator
455455
*/
456456
public CSVFormat withLineSeparator(final char lineSeparator) {
457-
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
457+
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
458458
ignoreSurroundingSpaces, ignoreEmptyLines, String.valueOf(lineSeparator), header);
459459
}
460460

@@ -467,7 +467,7 @@ public CSVFormat withLineSeparator(final char lineSeparator) {
467467
* @return A copy of this format using the specified output line separator
468468
*/
469469
public CSVFormat withLineSeparator(final String lineSeparator) {
470-
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
470+
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
471471
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
472472
}
473473

@@ -480,7 +480,7 @@ public CSVFormat withLineSeparator(final String lineSeparator) {
480480
* @return A copy of this format using the specified output line separator
481481
*/
482482
public CSVFormat withQuotePolicy(final Quote quotePolicy) {
483-
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
483+
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
484484
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
485485
}
486486

@@ -508,7 +508,7 @@ String[] getHeader() {
508508
* @return A copy of this format using the specified header
509509
*/
510510
public CSVFormat withHeader(final String... header) {
511-
return new CSVFormat(delimiter, encapsulator, quotePolicy, commentStart, escape,
511+
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
512512
ignoreSurroundingSpaces, ignoreEmptyLines, lineSeparator, header);
513513
}
514514

@@ -549,7 +549,7 @@ public String toString() {
549549
}
550550
if (isEncapsulating()) {
551551
sb.append(' ');
552-
sb.append("Encapsulator=<").append(encapsulator).append('>');
552+
sb.append("Encapsulator=<").append(quoteChar).append('>');
553553
}
554554
if (isCommentingEnabled()) {
555555
sb.append(' ');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void printAndEncapsulate(final CharSequence value, final int offset, final int l
201201
printDelimiter();
202202

203203
final char delim = format.getDelimiter();
204-
final char encapsulator = format.getEncapsulator();
204+
final char encapsulator = format.getQuoteChar();
205205

206206
if (len <= 0) {
207207
// always quote an empty token that is the first

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ abstract class Lexer {
5757
this.in = in;
5858
this.delimiter = format.getDelimiter();
5959
this.escape = mapNullToDisabled(format.getEscape());
60-
this.encapsulator = mapNullToDisabled(format.getEncapsulator());
60+
this.encapsulator = mapNullToDisabled(format.getQuoteChar());
6161
this.commmentStart = mapNullToDisabled(format.getCommentStart());
6262
this.ignoreSurroundingSpaces = format.getIgnoreSurroundingSpaces();
6363
this.ignoreEmptyLines = format.getIgnoreEmptyLines();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void testImmutalibity() {
4747
format.withQuotePolicy(Quote.ALL);
4848

4949
assertEquals('!', format.getDelimiter());
50-
assertEquals('!', format.getEncapsulator().charValue());
50+
assertEquals('!', format.getQuoteChar().charValue());
5151
assertEquals('!', format.getCommentStart().charValue());
5252
assertEquals('!', format.getEscape().charValue());
5353
assertEquals(CRLF, format.getLineSeparator());
@@ -63,7 +63,7 @@ public void testMutators() {
6363
final CSVFormat format = new CSVFormat('!', '!', null, '!', '!', true, true, CRLF, null);
6464

6565
assertEquals('?', format.withDelimiter('?').getDelimiter());
66-
assertEquals('?', format.withEncapsulator('?').getEncapsulator().charValue());
66+
assertEquals('?', format.withEncapsulator('?').getQuoteChar().charValue());
6767
assertEquals('?', format.withCommentStart('?').getCommentStart().charValue());
6868
assertEquals("?", format.withLineSeparator("?").getLineSeparator());
6969
assertEquals('?', format.withEscape('?').getEscape().charValue());
@@ -171,7 +171,7 @@ public void testSerialization() throws Exception {
171171

172172
assertNotNull(format);
173173
assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
174-
assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
174+
assertEquals("encapsulator", CSVFormat.DEFAULT.getQuoteChar(), format.getQuoteChar());
175175
assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
176176
assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
177177
assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Token nextToken(Token tkn) throws IOException {
108108
//noop: tkn.content.append("");
109109
tkn.type = EORECORD;
110110
tkn.isReady = true;
111-
} else if (c == format.getEncapsulator()) {
111+
} else if (c == format.getQuoteChar()) {
112112
// consume encapsulated token
113113
encapsulatedTokenLexer(tkn, c);
114114
} else if (isEndOfFile(c)) {
@@ -201,8 +201,8 @@ private Token encapsulatedTokenLexer(final Token tkn, int c) throws IOException
201201

202202
if (c == format.getEscape()) {
203203
tkn.content.append((char) readEscape());
204-
} else if (c == format.getEncapsulator()) {
205-
if (in.lookAhead() == format.getEncapsulator()) {
204+
} else if (c == format.getQuoteChar()) {
205+
if (in.lookAhead() == format.getQuoteChar()) {
206206
// double or escaped encapsulator -> add single encapsulator to token
207207
c = in.read();
208208
tkn.content.append((char) c);

0 commit comments

Comments
 (0)