Package com.univocity.parsers.csv
Class CsvFormat
java.lang.Object
com.univocity.parsers.common.Format
com.univocity.parsers.csv.CsvFormat
- All Implemented Interfaces:
Cloneable
The CSV format configuration. In addition to the default configuration in
Format
, the CSV format defines:
- delimiter (defaults to ','): the field delimiter character. Used to separate individual fields in a CSV record (where the record is usually a line of text with multiple fields).
e.g. the value a , b is parsed as [ a ][ b ]
- quote (defaults to '"'): character used for escaping values where the field delimiter is part of the value.
e.g. the value " a , b " is parsed as [ a , b ] (instead of [ a ][ b ]
- quoteEscape (defaults to '"'): character used for escaping the quote character inside an already quoted value
e.g. the value " "" a , b "" " is parsed as [ " a , b " ] (instead of [ " a ][ b " ] or [ "" a , b "" ])
- charToEscapeQuoteEscaping (defaults to '\0' - undefined): character used for escaping the escape for the quote character
e.g. if the quoteEscape and charToEscapeQuoteEscaping are set to '\', the value " \\\" a , b \\\" " is parsed as [ \" a , b \" ]
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal CsvFormat
clone()
final char
Returns the character used to escape the character used for escaping quotes defined bygetQuoteEscape()
.char
Returns the field delimiter character.Returns the field delimiter sequence.char
getQuote()
Returns the character used for escaping values where the field delimiter is part of the value.char
Returns the character used for escaping quotes inside an already quoted value.final boolean
isCharToEscapeQuoteEscaping
(char ch) Identifies whether or not a given character is used to escape the character used for escaping quotes defined bygetQuoteEscape()
.boolean
isDelimiter
(char ch) Identifies whether or not a given character represents a field delimiterboolean
isDelimiter
(String sequence) Identifies whether or not a given character represents a field delimiterboolean
isQuote
(char ch) Identifies whether or not a given character is used for escaping values where the field delimiter is part of the valueboolean
isQuoteEscape
(char ch) Identifies whether or not a given character is used for escaping quotes inside an already quoted value.final void
setCharToEscapeQuoteEscaping
(char charToEscapeQuoteEscaping) Defines the character used to escape the character used for escaping quotes defined bygetQuoteEscape()
.void
setDelimiter
(char delimiter) Defines the field delimiter character.void
setDelimiter
(String delimiter) Defines the field delimiter as a sequence of characters.void
setQuote
(char quote) Defines the character used for escaping values where the field delimiter is part of the value.void
setQuoteEscape
(char quoteEscape) Defines the character used for escaping quotes inside an already quoted value.Methods inherited from class com.univocity.parsers.common.Format
getComment, getLineSeparator, getLineSeparatorString, getNormalizedNewline, getSystemLineSeparator, isComment, isNewLine, setComment, setLineSeparator, setLineSeparator, setNormalizedNewline, toString
-
Field Details
-
quote
private char quote -
quoteEscape
private char quoteEscape -
delimiter
-
charToEscapeQuoteEscaping
-
-
Constructor Details
-
CsvFormat
public CsvFormat()
-
-
Method Details
-
getQuote
public char getQuote()Returns the character used for escaping values where the field delimiter is part of the value. Defaults to '"'- Returns:
- the quote character
-
setQuote
public void setQuote(char quote) Defines the character used for escaping values where the field delimiter is part of the value. Defaults to '"'- Parameters:
quote
- the quote character
-
isQuote
public boolean isQuote(char ch) Identifies whether or not a given character is used for escaping values where the field delimiter is part of the value- Parameters:
ch
- the character to be verified- Returns:
- true if the given character is the character used for escaping values, false otherwise
-
getQuoteEscape
public char getQuoteEscape()Returns the character used for escaping quotes inside an already quoted value. Defaults to '"'- Returns:
- the quote escape character
-
setQuoteEscape
public void setQuoteEscape(char quoteEscape) Defines the character used for escaping quotes inside an already quoted value. Defaults to '"'- Parameters:
quoteEscape
- the quote escape character
-
isQuoteEscape
public boolean isQuoteEscape(char ch) Identifies whether or not a given character is used for escaping quotes inside an already quoted value.- Parameters:
ch
- the character to be verified- Returns:
- true if the given character is the quote escape character, false otherwise
-
getDelimiter
public char getDelimiter()Returns the field delimiter character. Defaults to ','- Returns:
- the field delimiter character
-
getDelimiterString
Returns the field delimiter sequence.- Returns:
- the field delimiter as a
String
.
-
setDelimiter
public void setDelimiter(char delimiter) Defines the field delimiter character. Defaults to ','- Parameters:
delimiter
- the field delimiter character
-
setDelimiter
Defines the field delimiter as a sequence of characters. Defaults to ','- Parameters:
delimiter
- the field delimiter sequence.
-
isDelimiter
public boolean isDelimiter(char ch) Identifies whether or not a given character represents a field delimiter- Parameters:
ch
- the character to be verified- Returns:
- true if the given character is the field delimiter character, false otherwise
-
isDelimiter
Identifies whether or not a given character represents a field delimiter- Parameters:
sequence
- the character sequence to be verified- Returns:
- true if the given sequence is the field delimiter character sequence, false otherwise
-
getCharToEscapeQuoteEscaping
public final char getCharToEscapeQuoteEscaping()Returns the character used to escape the character used for escaping quotes defined bygetQuoteEscape()
. For example, if the quote escape is set to '\', and the quoted value ends with: \", as in the following example:[ " a\\", b ]
Then:- If the character to escape the '\' is undefined, the record won't be parsed. The parser will read characters: [a],[\],["],[,],[ ],[b] and throw an error because it cannot find a closing quote
- If the character to escape the '\' is defined as '\', the record will be read with 2 values: [a\] and [b]
- Returns:
- the character to escape the character used for escaping quotes defined
-
setCharToEscapeQuoteEscaping
public final void setCharToEscapeQuoteEscaping(char charToEscapeQuoteEscaping) Defines the character used to escape the character used for escaping quotes defined bygetQuoteEscape()
. For example, if the quote escape is set to '\', and the quoted value ends with: \", as in the following example:[ " a\\", b ]
Then:- If the character to escape the '\' is undefined, the record won't be parsed. The parser will read characters: [a],[\],["],[,],[ ],[b] and throw an error because it cannot find a closing quote
- If the character to escape the '\' is defined as '\', the record will be read with 2 values: [a\] and [b]
- Parameters:
charToEscapeQuoteEscaping
- the character to escape the character used for escaping quotes defined
-
isCharToEscapeQuoteEscaping
public final boolean isCharToEscapeQuoteEscaping(char ch) Identifies whether or not a given character is used to escape the character used for escaping quotes defined bygetQuoteEscape()
.- Parameters:
ch
- the character to be verified- Returns:
- true if the given character is used to escape the quote escape character, false otherwise
-
getConfiguration
- Specified by:
getConfiguration
in classFormat
-
clone
-