Package org.apache.hc.core5.util
Class Tokenizer
java.lang.Object
org.apache.hc.core5.util.Tokenizer
- Direct Known Subclasses:
TokenParser
Tokenizer that can be used as a foundation for more complex parsing routines.
Methods of this class are designed to produce near zero intermediate garbage
and make no intermediate copies of input data.
This class is immutable and thread safe.
- Since:
- 5.1
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
copyContent
(CharSequence buf, Tokenizer.Cursor cursor, BitSet delimiters, StringBuilder dst) Transfers content into the destination buffer until a whitespace character or any of the given delimiters is encountered.void
copyQuotedContent
(CharSequence buf, Tokenizer.Cursor cursor, StringBuilder dst) Transfers content enclosed with quote marks into the destination buffer.void
copyUnquotedContent
(CharSequence buf, Tokenizer.Cursor cursor, BitSet delimiters, StringBuilder dst) Transfers content into the destination buffer until a whitespace character, a quote, or any of the given delimiters is encountered.static BitSet
INIT_BITSET
(int... b) static boolean
isWhitespace
(char ch) parseContent
(CharSequence buf, Tokenizer.Cursor cursor, BitSet delimiters) Extracts from the sequence of chars a token terminated with any of the given delimiters or a whitespace characters.parseToken
(CharSequence buf, Tokenizer.Cursor cursor, BitSet delimiters) Extracts from the sequence of chars a token terminated with any of the given delimiters discarding semantically insignificant whitespace characters.parseValue
(CharSequence buf, Tokenizer.Cursor cursor, BitSet delimiters) Extracts from the sequence of chars a value which can be enclosed in quote marks and terminated with any of the given delimiters discarding semantically insignificant whitespace characters.void
skipWhiteSpace
(CharSequence buf, Tokenizer.Cursor cursor) Skips semantically insignificant whitespace characters and moves the cursor to the closest non-whitespace character.
-
Field Details
-
DQUOTE
public static final char DQUOTEDouble quote- See Also:
-
ESCAPE
public static final char ESCAPEBackward slash / escape character- See Also:
-
CR
public static final int CR- See Also:
-
LF
public static final int LF- See Also:
-
SP
public static final int SP- See Also:
-
HT
public static final int HT- See Also:
-
INSTANCE
-
-
Constructor Details
-
Tokenizer
public Tokenizer()
-
-
Method Details
-
INIT_BITSET
-
isWhitespace
public static boolean isWhitespace(char ch) -
parseContent
Extracts from the sequence of chars a token terminated with any of the given delimiters or a whitespace characters.- Parameters:
buf
- buffer with the sequence of chars to be parsedcursor
- defines the bounds and current position of the bufferdelimiters
- set of delimiting characters. Can benull
if the token is not delimited by any character.
-
parseToken
Extracts from the sequence of chars a token terminated with any of the given delimiters discarding semantically insignificant whitespace characters.- Parameters:
buf
- buffer with the sequence of chars to be parsedcursor
- defines the bounds and current position of the bufferdelimiters
- set of delimiting characters. Can benull
if the token is not delimited by any character.
-
parseValue
Extracts from the sequence of chars a value which can be enclosed in quote marks and terminated with any of the given delimiters discarding semantically insignificant whitespace characters.- Parameters:
buf
- buffer with the sequence of chars to be parsedcursor
- defines the bounds and current position of the bufferdelimiters
- set of delimiting characters. Can benull
if the value is not delimited by any character.
-
skipWhiteSpace
Skips semantically insignificant whitespace characters and moves the cursor to the closest non-whitespace character.- Parameters:
buf
- buffer with the sequence of chars to be parsedcursor
- defines the bounds and current position of the buffer
-
copyContent
public void copyContent(CharSequence buf, Tokenizer.Cursor cursor, BitSet delimiters, StringBuilder dst) Transfers content into the destination buffer until a whitespace character or any of the given delimiters is encountered.- Parameters:
buf
- buffer with the sequence of chars to be parsedcursor
- defines the bounds and current position of the bufferdelimiters
- set of delimiting characters. Can benull
if the value is delimited by a whitespace only.dst
- destination buffer
-
copyUnquotedContent
public void copyUnquotedContent(CharSequence buf, Tokenizer.Cursor cursor, BitSet delimiters, StringBuilder dst) Transfers content into the destination buffer until a whitespace character, a quote, or any of the given delimiters is encountered.- Parameters:
buf
- buffer with the sequence of chars to be parsedcursor
- defines the bounds and current position of the bufferdelimiters
- set of delimiting characters. Can benull
if the value is delimited by a whitespace or a quote only.dst
- destination buffer
-
copyQuotedContent
Transfers content enclosed with quote marks into the destination buffer.- Parameters:
buf
- buffer with the sequence of chars to be parsedcursor
- defines the bounds and current position of the bufferdst
- destination buffer
-