Class Literals
- Author:
- Curtis Rueden
-
Method Summary
Modifier and TypeMethodDescriptionstatic Number
Parses a binary literal (e.g.,0b010101000011
).static Number
parseBinary
(CharSequence s, Position pos) Parses a binary literal (e.g.,0b010101000011
).static Boolean
Parses a boolean literal (i.e., true and false).static Boolean
parseBoolean
(CharSequence s, Position pos) Parses a boolean literal (i.e., true and false).static Number
Parses a decimal literal (integer or otherwise; e.g.,1234567890
,1234.0987
or1.2e34
).static Number
parseDecimal
(CharSequence s, Position pos) Parses a decimal literal (e.g.,1234.0987
or1.2e34
).static Number
Parses a hexidecimal literal (e.g.,0xfedcba9876543210
).static Number
parseHex
(CharSequence s, Position pos) Parses a hexidecimal literal (e.g.,0xfedcba9876543210
).static Object
Parses a literal of any known type (booleans, strings and numbers).static Object
parseLiteral
(CharSequence s, Position pos) Parses a literal of any known type (booleans, strings and numbers).static Number
Parses a numeric literal of any known type.static Number
parseNumber
(CharSequence s, Position pos) Parses a numeric literal of any known type.static Number
Parses an octal literal (e.g.,01234567
).static Number
parseOctal
(CharSequence s, Position pos) Parses an octal literal (e.g.,01234567
).static String
Parses a string literal which is enclosed in single or double quotes.static String
parseString
(CharSequence s, Position pos) Parses a string literal which is enclosed in single or double quotes.
-
Method Details
-
parseBoolean
Parses a boolean literal (i.e., true and false).- Parameters:
s
- The string from which the boolean literal should be parsed.- Returns:
- The parsed boolean value—either
Boolean.TRUE
orBoolean.FALSE
— or null if the string does not begin with a boolean literal.
-
parseString
Parses a string literal which is enclosed in single or double quotes.For literals in double quotes, this parsing mechanism is intended to be as close as possible to the numeric literals supported by the Java programming language itself. Literals in single quotes are completely verbatim, with no escaping performed.
- Parameters:
s
- The string from which the string literal should be parsed.- Returns:
- The parsed string value, unescaped according to Java conventions. Returns null if the string does not begin with a single or double quote.
-
parseHex
Parses a hexidecimal literal (e.g.,0xfedcba9876543210
).- Parameters:
s
- The string from which the numeric literal should be parsed.- Returns:
- The parsed numeric value—an
Integer
if sufficiently small, or aLong
if needed or if theL
suffix is given; or aBigInteger
if the value is too large even forlong
.
-
parseBinary
Parses a binary literal (e.g.,0b010101000011
).- Parameters:
s
- The string from which the numeric literal should be parsed.- Returns:
- The parsed numeric value—an
Integer
if sufficiently small, or aLong
if needed or if theL
suffix is given; or aBigInteger
if the value is too large even forlong
.
-
parseOctal
Parses an octal literal (e.g.,01234567
).- Parameters:
s
- The string from which the numeric literal should be parsed.- Returns:
- The parsed numeric value—an
Integer
if sufficiently small, or aLong
if needed or if theL
suffix is given; or aBigInteger
if the value is too large even forlong
.
-
parseDecimal
Parses a decimal literal (integer or otherwise; e.g.,1234567890
,1234.0987
or1.2e34
).- Parameters:
s
- The string from which the numeric literal should be parsed.- Returns:
- The parsed numeric value, of a type consistent with Java's support
for numeric primitives—or for values outside the normal range
of Java primitives,
BigInteger
orBigDecimal
as appropriate. Returns null if the string does not begin with the numeric literal telltale of a 0-9 digit with optional minus.
-
parseNumber
Parses a numeric literal of any known type.This parsing mechanism is intended to be as close as possible to the numeric literals supported by the Java programming language itself.
- Parameters:
s
- The string from which the numeric literal should be parsed.- Returns:
- The parsed numeric value, of a type consistent with Java's support
for numeric primitives—or for values outside the normal range
of Java primitives,
BigInteger
orBigDecimal
as appropriate. Returns null if the string does not begin with the numeric literal telltale of a 0-9 digit with optional minus.
-
parseLiteral
Parses a literal of any known type (booleans, strings and numbers). -
parseBoolean
Parses a boolean literal (i.e., true and false).- Parameters:
s
- The string from which the boolean literal should be parsed.pos
- The offset from which the literal should be parsed. If parsing is successful, the position will be advanced to the next index after the parsed literal.- Returns:
- The parsed boolean value—either
Boolean.TRUE
orBoolean.FALSE
— or null if the string does not begin with a boolean literal.
-
parseString
Parses a string literal which is enclosed in single or double quotes.For literals in double quotes, this parsing mechanism is intended to be as close as possible to the numeric literals supported by the Java programming language itself. Literals in single quotes are completely verbatim, with no escaping performed.
- Parameters:
s
- The string from which the string literal should be parsed.pos
- The offset from which the literal should be parsed. If parsing is successful, the position will be advanced to the next index after the parsed literal.- Returns:
- The parsed string value, unescaped according to Java conventions. Returns null if the string does not begin with a single or double quote.
-
parseHex
Parses a hexidecimal literal (e.g.,0xfedcba9876543210
).- Parameters:
s
- The string from which the numeric literal should be parsed.pos
- The offset from which the literal should be parsed. If parsing is successful, the position will be advanced to the next index after the parsed literal.- Returns:
- The parsed numeric value—an
Integer
if sufficiently small, or aLong
if needed or if theL
suffix is given; or aBigInteger
if the value is too large even forlong
; ornull
if the string does not begin with the numeric literal telltale of a 0-9 digit with optional minus.
-
parseBinary
Parses a binary literal (e.g.,0b010101000011
).- Parameters:
s
- The string from which the numeric literal should be parsed.pos
- The offset from which the literal should be parsed. If parsing is successful, the position will be advanced to the next index after the parsed literal.- Returns:
- The parsed numeric value—an
Integer
if sufficiently small, or aLong
if needed or if theL
suffix is given; or aBigInteger
if the value is too large even forlong
; ornull
if the string does not begin with the numeric literal telltale of a 0-9 digit with optional minus.
-
parseOctal
Parses an octal literal (e.g.,01234567
).- Parameters:
s
- The string from which the numeric literal should be parsed.pos
- The offset from which the literal should be parsed. If parsing is successful, the position will be advanced to the next index after the parsed literal.- Returns:
- The parsed numeric value—an
Integer
if sufficiently small, or aLong
if needed or if theL
suffix is given; or aBigInteger
if the value is too large even forlong
; ornull
if the string does not begin with the numeric literal telltale of a 0-9 digit with optional minus.
-
parseDecimal
Parses a decimal literal (e.g.,1234.0987
or1.2e34
).- Parameters:
s
- The string from which the numeric literal should be parsed.pos
- The offset from which the literal should be parsed. If parsing is successful, the position will be advanced to the next index after the parsed literal.- Returns:
- The parsed numeric value, of a type consistent with Java's support
for numeric primitives—or for values outside the normal range
of Java primitives,
BigInteger
orBigDecimal
as appropriate. Returns null if the string does not begin with the numeric literal telltale of a 0-9 digit with optional minus.
-
parseNumber
Parses a numeric literal of any known type.This parsing mechanism is intended to be as close as possible to the numeric literals supported by the Java programming language itself.
- Parameters:
s
- The string from which the numeric literal should be parsed.pos
- The offset from which the literal should be parsed. If parsing is successful, the position will be advanced to the next index after the parsed literal.- Returns:
- The parsed numeric value, of a type consistent with Java's support
for numeric primitives—or for values outside the normal range
of Java primitives,
BigInteger
orBigDecimal
as appropriate. Returns null if the string does not begin with the numeric literal telltale of a 0-9 digit with optional minus.
-
parseLiteral
Parses a literal of any known type (booleans, strings and numbers).- Parameters:
s
- The string from which the literal should be parsed.pos
- The offset from which the literal should be parsed. If parsing is successful, the position will be advanced to the next index after the parsed literal.- Returns:
- The parsed value, of a type consistent with Java's support for
literals: either
Boolean
,String
or a concreteNumber
subclass. Returns null if the string does not match the syntax of a known literal. - See Also:
-