Top Description Fields Constructors Methods
org.apache.commons.jexl2.parser

public Class StringParser

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.commons.jexl2.parser.JexlParser

Common constant strings utilities.

This package methods read JEXL string literals and handle escaping through the 'backslash' (ie: \) character. Escaping is used to neutralize string delimiters (the single and double quotes) and read Unicode hexadecimal encoded characters.

The only escapable characters are the single and double quotes - ''' and '"' -, a Unicode sequence starting with 'u' followed by 4 hexadecimals and the backslash character - '\' - itself.

A sequence where '\' occurs before any non-escapable character or sequence has no effect, the sequence output being the same as the input.

Field Summary

Modifier and TypeField and Description
private static final int
BASE10

The base 10 offset used to convert hexa characters to decimal.

private static final char
FIRST_ASCII

The first printable 7bits ascii character.

private static final char
LAST_ASCII

The last 7bits ascii character.

private static final int
SHIFT

Initial shift value for composing a Unicode char from 4 nibbles (16 - 4).

private static final int
UCHAR_LEN

The length of an escaped unicode sequence.

Constructor Summary

AccessConstructor and Description
public
StringParser()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the built string
buildString
(CharSequence
the string to build from
str
,
boolean
whether the separator, the first character, should be considered
eatsep
)

Builds a string, handles escaping through '\' syntax.

public static String

Returns:

the escaped representation
escapeString
(String
the string to escape
str
,
char delim)

Escapes a String representation, expand non-ASCII characters as Unicode escape sequence.

private static int

Returns:

the last character offset handled in origin
read
(StringBuilder
the destination buffer to copy characters into
strb
,
CharSequence
the origin
str
,
int
the relative offset in str to begin reading
begin
,
int
the relative offset in str to end reading
end
,
char
the separator, single or double quote, marking end of string
sep
)

Read the remainder of a string till a given separator, handles escaping through '\' syntax.

public static int

Returns:

the offset in origin
readString
(StringBuilder
the destination buffer to copy characters into
strb
,
CharSequence
the origin
str
,
int
the offset into the origin
index
,
char
the separator, single or double quote, marking end of string
sep
)

Read the remainder of a string till a given separator, handles escaping through '\' syntax.

private static int

Returns:

0 if char could not be read, 4 otherwise
readUnicodeChar
(StringBuilder
the builder to write the character to
strb
,
CharSequence
the sequence
str
,
int
the begin offset in sequence (after the '\\u')
begin
)

Reads a Unicode escape character.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BASE10back to summary
private static final int BASE10

The base 10 offset used to convert hexa characters to decimal.

FIRST_ASCIIback to summary
private static final char FIRST_ASCII

The first printable 7bits ascii character.

LAST_ASCIIback to summary
private static final char LAST_ASCII

The last 7bits ascii character.

SHIFTback to summary
private static final int SHIFT

Initial shift value for composing a Unicode char from 4 nibbles (16 - 4).

UCHAR_LENback to summary
private static final int UCHAR_LEN

The length of an escaped unicode sequence.

Constructor Detail

StringParserback to summary
public StringParser()

Default constructor.

Method Detail

buildStringback to summary
public static String buildString(CharSequence str, boolean eatsep)

Builds a string, handles escaping through '\' syntax.

Parameters
str:CharSequence

the string to build from

eatsep:boolean

whether the separator, the first character, should be considered

Returns:String

the built string

escapeStringback to summary
public static String escapeString(String str, char delim)

Escapes a String representation, expand non-ASCII characters as Unicode escape sequence.

Parameters
str:String

the string to escape

Returns:String

the escaped representation

readback to summary
private static int read(StringBuilder strb, CharSequence str, int begin, int end, char sep)

Read the remainder of a string till a given separator, handles escaping through '\' syntax.

Parameters
strb:StringBuilder

the destination buffer to copy characters into

str:CharSequence

the origin

begin:int

the relative offset in str to begin reading

end:int

the relative offset in str to end reading

sep:char

the separator, single or double quote, marking end of string

Returns:int

the last character offset handled in origin

readStringback to summary
public static int readString(StringBuilder strb, CharSequence str, int index, char sep)

Read the remainder of a string till a given separator, handles escaping through '\' syntax.

Parameters
strb:StringBuilder

the destination buffer to copy characters into

str:CharSequence

the origin

index:int

the offset into the origin

sep:char

the separator, single or double quote, marking end of string

Returns:int

the offset in origin

readUnicodeCharback to summary
private static int readUnicodeChar(StringBuilder strb, CharSequence str, int begin)

Reads a Unicode escape character.

Parameters
strb:StringBuilder

the builder to write the character to

str:CharSequence

the sequence

begin:int

the begin offset in sequence (after the '\\u')

Returns:int

0 if char could not be read, 4 otherwise