Java Reference
In-Depth Information
After the quotes are escaped, the string being parsed is actually the following:
"LU",86.25,"11/4/1998","2:19PM",+4.0625
Running CSVSimple yields the following output:
> java csv.CSVSimple
LU
86.25
11/4/1998
2:19PM
+4.0625
>
But what about the CSV class itself? The code in Example 3-11 started as a translation of a
CSV program written in C++ by Brian W. Kernighan and Rob Pike that appeared in their
book The Practice of Programming (Addison-Wesley). Their version commingled the input
processing with the parsing; my CSV class does only the parsing because the input could be
coming from any of a variety of sources. And it has been substantially rewritten over time.
The main work is done in parse() , which delegates handling of individual fields to ad-
vquoted() in cases where the field begins with a quote; otherwise, to advplain() .
Example 3-11. CSV.java
// package com.darwinsys.csv;
public
public class
class CSVImport
CSVImport implements
implements CSVParser {
public
public static
static final
final char
char DEFAULT_SEP = ',' ;
/** Construct a CSV parser, with the default separator (`,'). */
public
public CSVImport () {
this
this ( DEFAULT_SEP );
}
/** Construct a CSV parser with a given separator.
* @param sep The single char for the separator (not a list of
* separator characters)
*/
public
public CSVImport ( char
char sep ) {
fieldSep = sep ;
}
Search WWH ::




Custom Search