Class Literals
- Author:
- Curtis Rueden
-
Method Summary
Modifier and TypeMethodDescriptionstatic NumberParses a binary literal (e.g.,0b010101000011).static NumberparseBinary(CharSequence s, Position pos) Parses a binary literal (e.g.,0b010101000011).static BooleanParses a boolean literal (i.e., true and false).static BooleanparseBoolean(CharSequence s, Position pos) Parses a boolean literal (i.e., true and false).static NumberParses a decimal literal (integer or otherwise; e.g.,1234567890,1234.0987or1.2e34).static NumberparseDecimal(CharSequence s, Position pos) Parses a decimal literal (e.g.,1234.0987or1.2e34).static NumberParses a hexidecimal literal.static NumberparseHex(CharSequence s, Position pos) Parses a hexidecimal literal.static ObjectParses a literal of any known type (booleans, strings and numbers).static ObjectparseLiteral(CharSequence s, Position pos) Parses a literal of any known type (booleans, strings and numbers).static NumberParses a numeric literal of any known type.static NumberparseNumber(CharSequence s, Position pos) Parses a numeric literal of any known type.static NumberParses an octal literal (e.g.,01234567).static NumberparseOctal(CharSequence s, Position pos) Parses an octal literal (e.g.,01234567).static StringParses a string literal which is enclosed in single or double quotes.static StringparseString(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.TRUEorBoolean.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. Both hexadecimal integer (e.g.,0xfedcba9876543210) and hexidecimal floating point (e.g.,0xfedcba.98765432p10f) are supported.- Parameters:
s- The string from which the numeric literal should be parsed.- Returns:
- The parsed numeric value. For hexidecimal integers, returns an
Integerif sufficiently small; or aLongif needed or if theLsuffix is given; or aBigIntegerif the value is too large even forlong. For hexidecimal floating point, returns aFloatif sufficiently small and theFsuffix is given; or aDoubleotherwise (theDsuffix is optional).
-
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
Integerif sufficiently small, or aLongif needed or if theLsuffix is given; or aBigIntegerif 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
Integerif sufficiently small, or aLongif needed or if theLsuffix is given; or aBigIntegerif the value is too large even forlong.
-
parseDecimal
Parses a decimal literal (integer or otherwise; e.g.,1234567890,1234.0987or1.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,
BigIntegerorBigDecimalas appropriate. Returns null if the string does not begin with the numeric literal telltale of a 0-9 digit with optional leading sign.
-
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,
BigIntegerorBigDecimalas appropriate. Returns null if the string does not begin with the numeric literal telltale of a 0-9 digit with optional leading sign.
-
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.TRUEorBoolean.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. Both hexadecimal integer (e.g.,0xfedcba9876543210) and hexidecimal floating point (e.g.,0xfedcba.98765432p10f) are supported.- 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. For hexidecimal integers, returns an
Integerif sufficiently small; or aLongif needed or if theLsuffix is given; or aBigIntegerif the value is too large even forlong. For hexidecimal floating point, returns aFloatif sufficiently small and theFsuffix is given; or aDoubleotherwise (theDsuffix is optional). In either case, returnsnullif the string does not begin with the numeric literal telltale of a 0-9 digit with optional leading sign.
-
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
Integerif sufficiently small, or aLongif needed or if theLsuffix is given; or aBigIntegerif the value is too large even forlong; ornullif the string does not begin with the numeric literal telltale of a 0-9 digit with optional leading sign.
-
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
Integerif sufficiently small, or aLongif needed or if theLsuffix is given; or aBigIntegerif the value is too large even forlong; ornullif the string does not begin with the numeric literal telltale of a 0-9 digit with optional leading sign.
-
parseDecimal
Parses a decimal literal (e.g.,1234.0987or1.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,
BigIntegerorBigDecimalas appropriate. Returns null if the string does not begin with the numeric literal telltale of a 0-9 digit with optional leading sign.
-
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,
BigIntegerorBigDecimalas appropriate. Returns null if the string does not begin with the numeric literal telltale of a 0-9 digit with optional leading sign.
-
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,Stringor a concreteNumbersubclass. Returns null if the string does not match the syntax of a known literal. - See Also:
-