Top Description Inners Fields Methods
org.eclipse.jetty.util

public Interface QuotedStringTokenizer

Known Direct Implementers
org.eclipse.jetty.util.RFC9110QuotedStringTokenizer, org.eclipse.jetty.util.LegacyQuotedStringTokenizer
Imports
java.util.Iterator

A Tokenizer that splits a string into parts, allowing for quotes.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
public static final QuotedStringTokenizer
CSV

A QuotedStringTokenizer for comma separated values with optional white space.

Method Summary

Modifier and TypeMethod and Description
public static QuotedStringTokenizer.Builder
builder()

Returns: A Builder for a QuotedStringTokenizer.

public static boolean
isQuoted(String
The string to test
s
)

Returns: True if the string is quoted.

public boolean
needsQuoting(char
A character
c
)

Returns: True if a string containing the character should be quoted.

public default String

Returns:

quoted string
quote
(String
The string to quote.
s
)

Quote a string.

public void
quote(Appendable
The Appendable to append the quoted and escaped string into.
buffer
,
String
The String to quote.
input
)

Quote a string into an Appendable, escaping any characters that need to be escaped.

public String

Returns:

quoted string
quoteIfNeeded
(String
The string to quote.
s
)

Quote a string.

public void
quoteIfNeeded(StringBuilder
the buffer to append to
buf
,
String
the string to possibly quote
str
)

Append into buf the provided string, adding quotes if needed.

public Iterator<String>

Returns:

An iterator of token strings.
tokenize
(String
The string to be tokenized
string
)

Tokenize the passed string into an Iterator of tokens split from the string by delimiters.

public String

Returns:

unquoted string with escaped characters expanded.
unquote
(String
The string to unquote.
s
)

Unquote a string and expand any escaped characters

Field Detail

CSVback to summary
public static final QuotedStringTokenizer CSV

A QuotedStringTokenizer for comma separated values with optional white space.

Method Detail

builderback to summary
public static QuotedStringTokenizer.Builder builder()
Returns:QuotedStringTokenizer.Builder

A Builder for a QuotedStringTokenizer.

isQuotedback to summary
public static boolean isQuoted(String s)
Parameters
s:String

The string to test

Returns:boolean

True if the string is quoted.

needsQuotingback to summary
public boolean needsQuoting(char c)
Parameters
c:char

A character

Returns:boolean

True if a string containing the character should be quoted.

quoteback to summary
public 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:String

The string to quote.

Returns:String

quoted string

quoteback to summary
public void quote(Appendable buffer, String input)

Quote a string into an Appendable, escaping any characters that need to be escaped.

Parameters
buffer:Appendable

The Appendable to append the quoted and escaped string into.

input:String

The String to quote.

quoteIfNeededback to summary
public 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:String

The string to quote.

Returns:String

quoted string

quoteIfNeededback to summary
public 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:StringBuilder

the buffer to append to

str:String

the string to possibly quote

tokenizeback to summary
public 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:String

The string to be tokenized

Returns:Iterator<String>

An iterator of token strings.

unquoteback to summary
public String unquote(String s)

Unquote a string and expand any escaped characters

Parameters
s:String

The string to unquote.

Returns:String

unquoted string with escaped characters expanded.

org.eclipse.jetty.util back to summary

public Class QuotedStringTokenizer.Builder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private String
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public QuotedStringTokenizer.Builder

Returns:

this Builder
allowEmbeddedQuotes
()

If called, the built QuotedStringTokenizer will interpret quote characters within a token as initiating a sequence of quoted characters, rather than being part of the token value itself.

public QuotedStringTokenizer.Builder

Returns:

this Builder
allowEscapeOnlyForQuotes
()

If called, the built QuotedStringTokenizer will only allow escapes to be used with the quote character.

public QuotedStringTokenizer.Builder

Returns:

this Builder
allowSingleQuote
()

If called, the built QuotedStringTokenizer will allow quoting with the single quote character '.

public QuotedStringTokenizer
build()

Returns: The built immutable QuotedStringTokenizer.

public QuotedStringTokenizer.Builder
delimiters(String
A string containing the set of characters that are considered delimiters.
delim
)

Returns: this Builder

public QuotedStringTokenizer.Builder

Returns:

this Builder
ignoreOptionalWhiteSpace
()

If called, the built QuotedStringTokenizer will ignore optional white space characters before and after delimiters.

public QuotedStringTokenizer.Builder

Returns:

this Builder
legacy
()

If called, the built QuotedStringTokenizer will use the legacy implementation from prior to jetty-12.

public QuotedStringTokenizer.Builder

Returns:

this Builder
returnDelimiters
()

If called, the built QuotedStringTokenizer will return delimiter characters as individual tokens.

public QuotedStringTokenizer.Builder

Returns:

this Builder
returnQuotes
()

If called, the built QuotedStringTokenizer will return tokens with quotes interpreted but not removed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_delimback to summary
private String _delim
_embeddedQuotesback to summary
private boolean _embeddedQuotes
_escapeOnlyQuoteback to summary
private boolean _escapeOnlyQuote
_legacyback to summary
private boolean _legacy
_optionalWhiteSpaceback to summary
private boolean _optionalWhiteSpace
_returnDelimitersback to summary
private boolean _returnDelimiters
_returnQuotesback to summary
private boolean _returnQuotes
_singleQuotesback to summary
private boolean _singleQuotes

Constructor Detail

Builderback to summary
private Builder()

Method Detail

allowEmbeddedQuotesback to summary
public QuotedStringTokenizer.Builder allowEmbeddedQuotes()

If called, the built QuotedStringTokenizer will interpret quote characters within a token as initiating a sequence of quoted characters, rather than being part of the token value itself. For example the string name1=value1; name2="value;2" with ; delimiter, would result in two tokens: name1=value1 and name2=value;2. Without this option the result would be three tokens: name1=value1, name2="value and 2".

Returns:QuotedStringTokenizer.Builder

this Builder

allowEscapeOnlyForQuotesback to summary
public QuotedStringTokenizer.Builder allowEscapeOnlyForQuotes()

If called, the built QuotedStringTokenizer will only allow escapes to be used with the quote character. Specifically the escape character itself cannot be escaped. Any usage of the escape character, other than for quotes, is considered as a literal escape character. For example the string "test\"tokenizer\test" will be unquoted as test"tokenizer\test.

Returns:QuotedStringTokenizer.Builder

this Builder

allowSingleQuoteback to summary
public QuotedStringTokenizer.Builder allowSingleQuote()

If called, the built QuotedStringTokenizer will allow quoting with the single quote character '. This can only be used with legacy().

Returns:QuotedStringTokenizer.Builder

this Builder

buildback to summary
public QuotedStringTokenizer build()
Returns:QuotedStringTokenizer

The built immutable QuotedStringTokenizer.

delimitersback to summary
public QuotedStringTokenizer.Builder delimiters(String delim)
Parameters
delim:String

A string containing the set of characters that are considered delimiters.

Returns:QuotedStringTokenizer.Builder

this Builder

ignoreOptionalWhiteSpaceback to summary
public QuotedStringTokenizer.Builder ignoreOptionalWhiteSpace()

If called, the built QuotedStringTokenizer will ignore optional white space characters before and after delimiters. This is not supported together with legacy(). For example, the string a, b ,c with delimiter , will be tokenized with this option as a, b and c, all trimmed of spaces. Without this option, the second token would be b with one space before and after.

Returns:QuotedStringTokenizer.Builder

this Builder

legacyback to summary
public QuotedStringTokenizer.Builder legacy()

If called, the built QuotedStringTokenizer will use the legacy implementation from prior to jetty-12. The legacy implementation does not comply with any current RFC. Using legacy also implies allowEmbeddedQuotes().

Returns:QuotedStringTokenizer.Builder

this Builder

returnDelimitersback to summary
public QuotedStringTokenizer.Builder returnDelimiters()

If called, the built QuotedStringTokenizer will return delimiter characters as individual tokens.

Returns:QuotedStringTokenizer.Builder

this Builder

returnQuotesback to summary
public QuotedStringTokenizer.Builder returnQuotes()

If called, the built QuotedStringTokenizer will return tokens with quotes interpreted but not removed.

Returns:QuotedStringTokenizer.Builder

this Builder