@@ -36,8 +36,7 @@ public class CSVFormat implements Serializable {
3636 private final char encapsulator ;
3737 private final char commentStart ;
3838 private final char escape ;
39- private final boolean leadingSpacesIgnored ;
40- private final boolean trailingSpacesIgnored ;
39+ private final boolean surroundingSpacesIgnored ; // Should leading/trailing spaces be ignored around values?
4140 private final boolean emptyLinesIgnored ;
4241 private final String lineSeparator ; // for outputs
4342 private final String [] header ;
@@ -55,7 +54,7 @@ public class CSVFormat implements Serializable {
5554 * Starting format with no settings defined; used for creating other formats from scratch.
5655 */
5756 private static CSVFormat PRISTINE =
58- new CSVFormat (DISABLED , DISABLED , DISABLED , DISABLED , false , false , false , null , null );
57+ new CSVFormat (DISABLED , DISABLED , DISABLED , DISABLED , false , false , null , null );
5958
6059 /**
6160 * Standard comma separated format, as for {@link #RFC4180} but allowing blank lines.
@@ -113,8 +112,7 @@ public class CSVFormat implements Serializable {
113112 PRISTINE
114113 .withDelimiter ('\t' )
115114 .withEncapsulator ('"' )
116- .withLeadingSpacesIgnored (true )
117- .withTrailingSpacesIgnored (true )
115+ .withSurroundingSpacesIgnored (true )
118116 .withEmptyLinesIgnored (true )
119117 .withLineSeparator (CRLF )
120118 ;
@@ -142,8 +140,7 @@ public class CSVFormat implements Serializable {
142140 * @param encapsulator the char used as value encapsulation marker
143141 * @param commentStart the char used for comment identification
144142 * @param escape the char used to escape special characters in values
145- * @param leadingSpacesIgnored <tt>true</tt> when leading whitespaces should be ignored
146- * @param trailingSpacesIgnored <tt>true</tt> when trailing whitespaces should be ignored
143+ * @param surroundingSpacesIgnored <tt>true</tt> when whitespaces enclosing values should be ignored
147144 * @param emptyLinesIgnored <tt>true</tt> when the parser should skip emtpy lines
148145 * @param lineSeparator the line separator to use for output
149146 * @param header the header
@@ -153,17 +150,15 @@ public class CSVFormat implements Serializable {
153150 char encapsulator ,
154151 char commentStart ,
155152 char escape ,
156- boolean leadingSpacesIgnored ,
157- boolean trailingSpacesIgnored ,
153+ boolean surroundingSpacesIgnored ,
158154 boolean emptyLinesIgnored ,
159155 String lineSeparator ,
160156 String [] header ) {
161157 this .delimiter = delimiter ;
162158 this .encapsulator = encapsulator ;
163159 this .commentStart = commentStart ;
164160 this .escape = escape ;
165- this .leadingSpacesIgnored = leadingSpacesIgnored ;
166- this .trailingSpacesIgnored = trailingSpacesIgnored ;
161+ this .surroundingSpacesIgnored = surroundingSpacesIgnored ;
167162 this .emptyLinesIgnored = emptyLinesIgnored ;
168163 this .lineSeparator = lineSeparator ;
169164 this .header = header ;
@@ -226,7 +221,7 @@ public CSVFormat withDelimiter(char delimiter) {
226221 throw new IllegalArgumentException ("The delimiter cannot be a line break" );
227222 }
228223
229- return new CSVFormat (delimiter , encapsulator , commentStart , escape , leadingSpacesIgnored , trailingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
224+ return new CSVFormat (delimiter , encapsulator , commentStart , escape , surroundingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
230225 }
231226
232227 /**
@@ -250,7 +245,7 @@ public CSVFormat withEncapsulator(char encapsulator) {
250245 throw new IllegalArgumentException ("The encapsulator cannot be a line break" );
251246 }
252247
253- return new CSVFormat (delimiter , encapsulator , commentStart , escape , leadingSpacesIgnored , trailingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
248+ return new CSVFormat (delimiter , encapsulator , commentStart , escape , surroundingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
254249 }
255250
256251 boolean isEncapsulating () {
@@ -278,7 +273,7 @@ public CSVFormat withCommentStart(char commentStart) {
278273 throw new IllegalArgumentException ("The comment start character cannot be a line break" );
279274 }
280275
281- return new CSVFormat (delimiter , encapsulator , commentStart , escape , leadingSpacesIgnored , trailingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
276+ return new CSVFormat (delimiter , encapsulator , commentStart , escape , surroundingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
282277 }
283278
284279 /**
@@ -311,51 +306,20 @@ public CSVFormat withEscape(char escape) {
311306 throw new IllegalArgumentException ("The escape character cannot be a line break" );
312307 }
313308
314- return new CSVFormat (delimiter , encapsulator , commentStart , escape , leadingSpacesIgnored , trailingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
309+ return new CSVFormat (delimiter , encapsulator , commentStart , escape , surroundingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
315310 }
316311
317312 boolean isEscaping () {
318313 return this .escape != DISABLED ;
319314 }
320315
321316 /**
322- * Tells if the spaces characters at the beginning of the values are ignored when parsing a file .
317+ * Specifies whether spaces around values are ignored when parsing input .
323318 *
324- * @return <tt>true</tt> if leading spaces are removed , <tt>false</tt> if they are preserved .
319+ * @return <tt>true</tt> if spaces around values are ignored , <tt>false</tt> if they are treated as part of the value .
325320 */
326- public boolean isLeadingSpacesIgnored () {
327- return leadingSpacesIgnored ;
328- }
329-
330- /**
331- * Returns a copy of this format with the specified left trimming behavior.
332- *
333- * @param leadingSpacesIgnored the left trimming behavior, <tt>true</tt> to remove the leading spaces,
334- * <tt>false</tt> to leave the spaces as is.
335- * @return A copy of this format with the specified left trimming behavior.
336- */
337- public CSVFormat withLeadingSpacesIgnored (boolean leadingSpacesIgnored ) {
338- return new CSVFormat (delimiter , encapsulator , commentStart , escape , leadingSpacesIgnored , trailingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
339- }
340-
341- /**
342- * Tells if the spaces characters at the end of the values are ignored when parsing a file.
343- *
344- * @return <tt>true</tt> if trailing spaces are removed, <tt>false</tt> if they are preserved.
345- */
346- public boolean isTrailingSpacesIgnored () {
347- return trailingSpacesIgnored ;
348- }
349-
350- /**
351- * Returns a copy of this format with the specified right trimming behavior.
352- *
353- * @param trailingSpacesIgnored the right trimming behavior, <tt>true</tt> to remove the trailing spaces,
354- * <tt>false</tt> to leave the spaces as is.
355- * @return A copy of this format with the specified right trimming behavior.
356- */
357- public CSVFormat withTrailingSpacesIgnored (boolean trailingSpacesIgnored ) {
358- return new CSVFormat (delimiter , encapsulator , commentStart , escape , leadingSpacesIgnored , trailingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
321+ public boolean isSurroundingSpacesIgnored () {
322+ return surroundingSpacesIgnored ;
359323 }
360324
361325 /**
@@ -366,7 +330,7 @@ public CSVFormat withTrailingSpacesIgnored(boolean trailingSpacesIgnored) {
366330 * @return A copy of this format with the specified trimming behavior.
367331 */
368332 public CSVFormat withSurroundingSpacesIgnored (boolean surroundingSpacesIgnored ) {
369- return new CSVFormat (delimiter , encapsulator , commentStart , escape , surroundingSpacesIgnored , surroundingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
333+ return new CSVFormat (delimiter , encapsulator , commentStart , escape , surroundingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
370334 }
371335
372336 /**
@@ -386,7 +350,7 @@ public boolean isEmptyLinesIgnored() {
386350 * @return A copy of this format with the specified empty line skipping behavior.
387351 */
388352 public CSVFormat withEmptyLinesIgnored (boolean emptyLinesIgnored ) {
389- return new CSVFormat (delimiter , encapsulator , commentStart , escape , leadingSpacesIgnored , trailingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
353+ return new CSVFormat (delimiter , encapsulator , commentStart , escape , surroundingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
390354 }
391355
392356 /**
@@ -406,7 +370,7 @@ public String getLineSeparator() {
406370 * @return A copy of this format using the specified output line separator
407371 */
408372 public CSVFormat withLineSeparator (String lineSeparator ) {
409- return new CSVFormat (delimiter , encapsulator , commentStart , escape , leadingSpacesIgnored , trailingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
373+ return new CSVFormat (delimiter , encapsulator , commentStart , escape , surroundingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
410374 }
411375
412376 String [] getHeader () {
@@ -428,7 +392,7 @@ String[] getHeader() {
428392 * @return A copy of this format using the specified header
429393 */
430394 public CSVFormat withHeader (String ... header ) {
431- return new CSVFormat (delimiter , encapsulator , commentStart , escape , leadingSpacesIgnored , trailingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
395+ return new CSVFormat (delimiter , encapsulator , commentStart , escape , surroundingSpacesIgnored , emptyLinesIgnored , lineSeparator , header );
432396 }
433397
434398 /**
0 commit comments