Interface QuotedStringTokenizer

All Known Implementing Classes:
LegacyQuotedStringTokenizer, RFC9110QuotedStringTokenizer

public interface QuotedStringTokenizer
A Tokenizer that splits a string into parts, allowing for quotes.
  • Field Details

    • CSV

      static final QuotedStringTokenizer CSV
      A QuotedStringTokenizer for comma separated values with optional white space.
  • Method Details

    • builder

      Returns:
      A Builder for a QuotedStringTokenizer.
    • isQuoted

      static boolean isQuoted(String s)
      Parameters:
      s - The string to test
      Returns:
      True if the string is quoted.
    • quote

      default String quote(String s)
      Quote a string. The string is quoted only if quoting is required due to embedded delimiters, quote characters or the empty string.
      Parameters:
      s - The string to quote.
      Returns:
      quoted string
    • quote

      void quote(Appendable buffer, String input)
      Quote a string into an Appendable, escaping any characters that need to be escaped.
      Parameters:
      buffer - The Appendable to append the quoted and escaped string into.
      input - The String to quote.
    • unquote

      String unquote(String s)
      Unquote a string and expand any escaped characters
      Parameters:
      s - The string to unquote.
      Returns:
      unquoted string with escaped characters expanded.
    • tokenize

      Iterator<String> tokenize(String string)
      Tokenize the passed string into an Iterator of tokens split from the string by delimiters. Tokenization is done as the iterator is advanced.
      Parameters:
      string - The string to be tokenized
      Returns:
      An iterator of token strings.
    • needsQuoting

      boolean needsQuoting(char c)
      Parameters:
      c - A character
      Returns:
      True if a string containing the character should be quoted.
    • quoteIfNeeded

      String quoteIfNeeded(String s)
      Quote a string. The string is quoted only if quoting is required due to embedded delimiters, quote characters or the empty string.
      Parameters:
      s - The string to quote.
      Returns:
      quoted string
    • quoteIfNeeded

      void quoteIfNeeded(StringBuilder buf, String str)
      Append into buf the provided string, adding quotes if needed.

      Quoting is determined if any of the characters in the delim are found in the input str.

      Parameters:
      buf - the buffer to append to
      str - the string to possibly quote