Class CsvFormat

java.lang.Object
com.univocity.parsers.common.Format
com.univocity.parsers.csv.CsvFormat
All Implemented Interfaces:
Cloneable

public class CsvFormat extends Format
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 Details

    • quote

      private char quote
    • quoteEscape

      private char quoteEscape
    • delimiter

      private String delimiter
    • charToEscapeQuoteEscaping

      private Character 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

      public String 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

      public void setDelimiter(String delimiter)
      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

      public boolean isDelimiter(String sequence)
      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 by getQuoteEscape(). 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]
      Defaults to '\0' (undefined)
      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 by getQuoteEscape(). 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]
      Defaults to '\0' (undefined)
      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 by getQuoteEscape().
      Parameters:
      ch - the character to be verified
      Returns:
      true if the given character is used to escape the quote escape character, false otherwise
    • getConfiguration

      protected TreeMap<String,Object> getConfiguration()
      Specified by:
      getConfiguration in class Format
    • clone

      public final CsvFormat clone()
      Overrides:
      clone in class Format