|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.glaivestone.toolbox.text.csv.CSVParser
Parser for processing text in CSV (comma-separated values) format.
A parser is configured with the separator string which separates field values in the text, along with a delimiter string which may be used to enclose field values. The default configuration uses comma as the field value separator and double-quote as the delimiter string.
Leading and trailing white space around a field value is always removed, unless the value is wrapped by the delimiter string so that significant leading or trailing white space is retained. Occurrences of the delimiter within the field value must be doubled-up; these are un-doubled by the parser to return the value containing the embedded delimiter.
The value for a field is always returned as a String
instance,
possibly empty. A field value returned by the parser is never null
.
The standard usage pattern is to instantiate a CSVParser
configured with the desired options for the field separator character
and the field value delimiter, then use it to parse CSV formatted text
lines into the field values. Clients may use either the
getValues(String)
service to parse the text into a List
containing the field values or the getStringValues(String)
service to parse the text into a String[]
array containing
the field values.
Constructor Summary | |
CSVParser()
Construct a new CSVParser which parses text tokens
separated by the default comma separator string. |
|
CSVParser(java.lang.String aSeparator,
char stringDelimiter)
Construct a new CSVParser which parses text tokens
separated by the specified separator string. |
Method Summary | |
java.lang.String[] |
getStringValues(java.lang.String aString)
Answer a list of the string values encoded in the CSV formatted string. |
java.util.List |
getValues(java.lang.String aString)
Answer a list of the string values encoded in the given CSV formatted string. |
void |
setDelimiter(char stringDelimiter)
Specify the character which is used as a token delimiter. |
void |
setSeparator(java.lang.String aSeparator)
Specify the token separator. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CSVParser()
CSVParser
which parses text tokens
separated by the default comma separator string.
public CSVParser(java.lang.String aSeparator, char stringDelimiter)
CSVParser
which parses text tokens
separated by the specified separator string.
Method Detail |
public java.lang.String[] getStringValues(java.lang.String aString)
public java.util.List getValues(java.lang.String aString)
public void setSeparator(java.lang.String aSeparator)
public void setDelimiter(char stringDelimiter)
|
GFL 1.1 API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |