2727 * Parses CSV files according to the specified configuration.
2828 *
2929 * Because CSV appears in many different dialects, the parser supports many
30- * configuration settings by allowing the specification of a {@link CSVStrategy }.
30+ * configuration settings by allowing the specification of a {@link CSVFormat }.
3131 *
3232 * <p>Parsing of a csv-string having tabs as separators,
3333 * '"' as an optional value encapsulator, and comments starting with '#':</p>
3434 * <pre>
3535 * String[][] data =
36- * (new CSVParser(new StringReader("a\tb\nc\td"), new CSVStrategy ('\t','"','#'))).getAllValues();
36+ * (new CSVParser(new StringReader("a\tb\nc\td"), new CSVFormat ('\t','"','#'))).getAllValues();
3737 * </pre>
3838 *
3939 * <p>Parsing of a csv-string in Excel CSV format</p>
4040 * <pre>
4141 * String[][] data =
42- * (new CSVParser(new StringReader("a;b\nc;d"), CSVStrategy.EXCEL_STRATEGY )).getAllValues();
42+ * (new CSVParser(new StringReader("a;b\nc;d"), CSVFormat.EXCEL )).getAllValues();
4343 * </pre>
4444 *
4545 * <p>
46- * Internal parser state is completely covered by the strategy
46+ * Internal parser state is completely covered by the format
4747 * and the reader-state.</p>
4848 *
4949 * <p>see <a href="package-summary.html">package documentation</a>
@@ -73,7 +73,7 @@ public class CSVParser {
7373 // the input stream
7474 private final ExtendedBufferedReader in ;
7575
76- private final CSVStrategy strategy ;
76+ private final CSVFormat format ;
7777
7878 // the following objects are shared to reduce garbage
7979 /**
@@ -117,31 +117,31 @@ Token reset() {
117117 // ======================================================
118118
119119 /**
120- * CSV parser using the default {@link CSVStrategy }.
120+ * CSV parser using the default {@link CSVFormat }.
121121 *
122122 * @param input a Reader containing "csv-formatted" input
123123 */
124124 public CSVParser (Reader input ) {
125- this (input , CSVStrategy . DEFAULT_STRATEGY );
125+ this (input , CSVFormat . DEFAULT );
126126 }
127127
128128 /**
129- * Customized CSV parser using the given {@link CSVStrategy }
129+ * Customized CSV parser using the given {@link CSVFormat }
130130 *
131131 * @param input a Reader containing "csv-formatted" input
132- * @param strategy the CSVStrategy used for CSV parsing
132+ * @param format the CSVFormat used for CSV parsing
133133 */
134- public CSVParser (Reader input , CSVStrategy strategy ) {
134+ public CSVParser (Reader input , CSVFormat format ) {
135135 this .in = new ExtendedBufferedReader (input );
136- this .strategy = strategy ;
136+ this .format = format ;
137137 }
138138
139139 // ======================================================
140140 // the parser
141141 // ======================================================
142142
143143 /**
144- * Parses the CSV according to the given strategy
144+ * Parses the CSV according to the given format
145145 * and returns the content as an array of records
146146 * (whereas records are arrays of single values).
147147 * <p/>
@@ -260,7 +260,7 @@ Token nextToken(Token tkn) throws IOException {
260260 c = in .readAgain ();
261261
262262 // empty line detection: eol AND (last char was EOL or beginning)
263- while (strategy .isEmptyLinesIgnored () && eol
263+ while (format .isEmptyLinesIgnored () && eol
264264 && (lastChar == '\n'
265265 || lastChar == '\r'
266266 || lastChar == ExtendedBufferedReader .UNDEFINED )
@@ -278,25 +278,25 @@ Token nextToken(Token tkn) throws IOException {
278278 }
279279
280280 // did we reach eof during the last iteration already ? TT_EOF
281- if (isEndOfFile (lastChar ) || (lastChar != strategy .getDelimiter () && isEndOfFile (c ))) {
281+ if (isEndOfFile (lastChar ) || (lastChar != format .getDelimiter () && isEndOfFile (c ))) {
282282 tkn .type = TT_EOF ;
283283 return tkn ;
284284 }
285285
286286 // important: make sure a new char gets consumed in each iteration
287287 while (!tkn .isReady && tkn .type != TT_EOF ) {
288288 // ignore whitespaces at beginning of a token
289- while (strategy .isLeadingSpacesIgnored () && isWhitespace (c ) && !eol ) {
289+ while (format .isLeadingSpacesIgnored () && isWhitespace (c ) && !eol ) {
290290 wsBuf .append ((char ) c );
291291 c = in .read ();
292292 eol = isEndOfLine (c );
293293 }
294294 // ok, start of token reached: comment, encapsulated, or token
295- if (c == strategy .getCommentStart ()) {
295+ if (c == format .getCommentStart ()) {
296296 // ignore everything till end of line and continue (incr linecount)
297297 in .readLine ();
298298 tkn = nextToken (tkn .reset ());
299- } else if (c == strategy .getDelimiter ()) {
299+ } else if (c == format .getDelimiter ()) {
300300 // empty token return TT_TOKEN("")
301301 tkn .type = TT_TOKEN ;
302302 tkn .isReady = true ;
@@ -305,7 +305,7 @@ Token nextToken(Token tkn) throws IOException {
305305 //noop: tkn.content.append("");
306306 tkn .type = TT_EORECORD ;
307307 tkn .isReady = true ;
308- } else if (c == strategy .getEncapsulator ()) {
308+ } else if (c == format .getEncapsulator ()) {
309309 // consume encapsulated token
310310 encapsulatedTokenLexer (tkn , c );
311311 } else if (isEndOfFile (c )) {
@@ -316,7 +316,7 @@ Token nextToken(Token tkn) throws IOException {
316316 } else {
317317 // next token must be a simple token
318318 // add removed blanks when not ignoring whitespace chars...
319- if (!strategy .isLeadingSpacesIgnored ()) {
319+ if (!format .isLeadingSpacesIgnored ()) {
320320 tkn .content .append (wsBuf );
321321 }
322322 simpleTokenLexer (tkn , c );
@@ -354,15 +354,15 @@ private Token simpleTokenLexer(Token tkn, int c) throws IOException {
354354 tkn .type = TT_EOF ;
355355 tkn .isReady = true ;
356356 break ;
357- } else if (c == strategy .getDelimiter ()) {
357+ } else if (c == format .getDelimiter ()) {
358358 // end of token
359359 tkn .type = TT_TOKEN ;
360360 tkn .isReady = true ;
361361 break ;
362- } else if (c == '\\' && strategy .isUnicodeEscapesInterpreted () && in .lookAhead () == 'u' ) {
362+ } else if (c == '\\' && format .isUnicodeEscapesInterpreted () && in .lookAhead () == 'u' ) {
363363 // interpret unicode escaped chars (like \u0070 -> p)
364364 tkn .content .append ((char ) unicodeEscapeLexer (c ));
365- } else if (c == strategy .getEscape ()) {
365+ } else if (c == format .getEscape ()) {
366366 tkn .content .append ((char ) readEscape (c ));
367367 } else {
368368 tkn .content .append ((char ) c );
@@ -371,7 +371,7 @@ private Token simpleTokenLexer(Token tkn, int c) throws IOException {
371371 c = in .read ();
372372 }
373373
374- if (strategy .isTrailingSpacesIgnored ()) {
374+ if (format .isTrailingSpacesIgnored ()) {
375375 tkn .content .trimTrailingWhitespace ();
376376 }
377377
@@ -400,20 +400,20 @@ private Token encapsulatedTokenLexer(Token tkn, int c) throws IOException {
400400 for (; ;) {
401401 c = in .read ();
402402
403- if (c == '\\' && strategy .isUnicodeEscapesInterpreted () && in .lookAhead () == 'u' ) {
403+ if (c == '\\' && format .isUnicodeEscapesInterpreted () && in .lookAhead () == 'u' ) {
404404 tkn .content .append ((char ) unicodeEscapeLexer (c ));
405- } else if (c == strategy .getEscape ()) {
405+ } else if (c == format .getEscape ()) {
406406 tkn .content .append ((char ) readEscape (c ));
407- } else if (c == strategy .getEncapsulator ()) {
408- if (in .lookAhead () == strategy .getEncapsulator ()) {
407+ } else if (c == format .getEncapsulator ()) {
408+ if (in .lookAhead () == format .getEncapsulator ()) {
409409 // double or escaped encapsulator -> add single encapsulator to token
410410 c = in .read ();
411411 tkn .content .append ((char ) c );
412412 } else {
413413 // token finish mark (encapsulator) reached: ignore whitespace till delimiter
414414 for (; ;) {
415415 c = in .read ();
416- if (c == strategy .getDelimiter ()) {
416+ if (c == format .getDelimiter ()) {
417417 tkn .type = TT_TOKEN ;
418418 tkn .isReady = true ;
419419 return tkn ;
@@ -512,12 +512,12 @@ private int readEscape(int c) throws IOException {
512512 // ======================================================
513513
514514 /**
515- * Obtain the specified CSV Strategy. This should not be modified .
515+ * Obtain the specified CSV format .
516516 *
517- * @return strategy currently being used
517+ * @return format currently being used
518518 */
519- public CSVStrategy getStrategy () {
520- return this .strategy ;
519+ public CSVFormat getFormat () {
520+ return this .format ;
521521 }
522522
523523 // ======================================================
@@ -528,7 +528,7 @@ public CSVStrategy getStrategy() {
528528 * @return true if the given char is a whitespace character
529529 */
530530 private boolean isWhitespace (int c ) {
531- return Character .isWhitespace ((char ) c ) && (c != strategy .getDelimiter ());
531+ return Character .isWhitespace ((char ) c ) && (c != format .getDelimiter ());
532532 }
533533
534534 /**
0 commit comments