Class CSVParser
java.lang.Object
ca.phon.csv.CSVParser
Processes data from a CSVTokenStream into arrays of Strings.
Uses the following grammar:
csvfile : record (NEWLINE record)* EOF ; record : field (SEPARATOR field)* ; field : escaped | unescaped ; escaped : QUOTE (TEXTDATA | NEWLINE | SEPARATOR | TWO_QUOTE)* QUOTE ; unescaped : TEXTDATA* ;
-
Constructor Summary
ConstructorsConstructorDescriptionCSVParser
(CSVTokenStream tokenStream, CSVQuoteType quoteChar, boolean trimSpaces) Constructs a new CSVParser with the specified token stream, quote character and boolean for trimming spaces -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(CSVParserListener listener) Adds a listener to the CSVParser.void
csvFile()
Parses the tokens for an entire CSV file.escaped()
Parses the tokens for an escaped field (cell surrounded by quotes) from a CSV file.field()
Parses the tokens for a single field (cell) from a CSV file.String[]
record()
Parses the tokens for a single record (row) from a CSV file.Parses the tokens for an unescaped field (cell not surrounded by quotes) from a CSV file.
-
Constructor Details
-
CSVParser
Constructs a new CSVParser with the specified token stream, quote character and boolean for trimming spaces- Parameters:
tokenStream
- An object containing a queue of tokens to be parsed.quoteChar
- An enum for which type of quote character is being used.trimSpaces
- If leading and trailing whitespace should be trimmed.
-
-
Method Details
-
addListener
Adds a listener to the CSVParser. -
csvFile
public void csvFile()Parses the tokens for an entire CSV file. -
record
Parses the tokens for a single record (row) from a CSV file.- Returns:
- An array of strings containing the contents of each field in the record.
-
field
Parses the tokens for a single field (cell) from a CSV file.- Returns:
- The contents of the field as a string.
-
escaped
Parses the tokens for an escaped field (cell surrounded by quotes) from a CSV file.- Returns:
- The escaped contents of the field as a string.
-
unescaped
Parses the tokens for an unescaped field (cell not surrounded by quotes) from a CSV file.- Returns:
- The contents of the field as a string.
-