public final class Literals extends Object
Modifier and Type | Method and Description |
---|---|
static Number |
parseBinary(CharSequence s)
Parses a binary literal (e.g.,
0b010101000011 ). |
static Number |
parseBinary(CharSequence s,
Position pos)
Parses a binary literal (e.g.,
0b010101000011 ). |
static Boolean |
parseBoolean(CharSequence s)
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 |
parseDecimal(CharSequence s)
Parses a decimal literal (integer or otherwise; e.g.,
1234567890 ,
1234.0987 or 1.2e34 ). |
static Number |
parseDecimal(CharSequence s,
Position pos)
Parses a decimal literal (e.g.,
1234.0987 or 1.2e34 ). |
static Number |
parseHex(CharSequence s)
Parses a hexidecimal literal (e.g.,
0xfedcba9876543210 ). |
static Number |
parseHex(CharSequence s,
Position pos)
Parses a hexidecimal literal (e.g.,
0xfedcba9876543210 ). |
static Object |
parseLiteral(CharSequence s)
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 |
parseNumber(CharSequence s)
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 |
parseOctal(CharSequence s)
Parses an octal literal (e.g.,
01234567 ). |
static Number |
parseOctal(CharSequence s,
Position pos)
Parses an octal literal (e.g.,
01234567 ). |
static String |
parseString(CharSequence s)
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.
|
public static Boolean parseBoolean(CharSequence s)
s
- The string from which the boolean literal should be parsed.Boolean.TRUE
or
Boolean.FALSE
— or null if the string does not begin
with a boolean literal.public static String parseString(CharSequence s)
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.
s
- The string from which the string literal should be parsed.public static Number parseHex(CharSequence s)
0xfedcba9876543210
).s
- The string from which the numeric literal should be parsed.Integer
if sufficiently
small, or a Long
if needed or if the L
suffix is
given; or a BigInteger
if the value is too large even for
long
.public static Number parseBinary(CharSequence s)
0b010101000011
).s
- The string from which the numeric literal should be parsed.Integer
if sufficiently
small, or a Long
if needed or if the L
suffix is
given; or a BigInteger
if the value is too large even for
long
.public static Number parseOctal(CharSequence s)
01234567
).s
- The string from which the numeric literal should be parsed.Integer
if sufficiently
small, or a Long
if needed or if the L
suffix is
given; or a BigInteger
if the value is too large even for
long
.public static Number parseDecimal(CharSequence s)
1234567890
,
1234.0987
or 1.2e34
).s
- The string from which the numeric literal should be parsed.BigInteger
or BigDecimal
as
appropriate. Returns null if the string does not begin with the
numeric literal telltale of a 0-9 digit with optional minus.public static Number parseNumber(CharSequence s)
This parsing mechanism is intended to be as close as possible to the numeric literals supported by the Java programming language itself.
s
- The string from which the numeric literal should be parsed.BigInteger
or BigDecimal
as
appropriate. Returns null if the string does not begin with the
numeric literal telltale of a 0-9 digit with optional minus.public static Object parseLiteral(CharSequence s)
s
- The string from which the literal should be parsed.Boolean
, String
or a concrete
Number
subclass. Returns null if the string does
not match the syntax of a known literal.parseBoolean(CharSequence)
,
parseString(CharSequence)
,
parseNumber(CharSequence)
public static Boolean parseBoolean(CharSequence s, Position pos)
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.Boolean.TRUE
or
Boolean.FALSE
— or null if the string does not begin
with a boolean literal.public static String parseString(CharSequence s, Position pos)
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.
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.public static Number parseHex(CharSequence s, Position pos)
0xfedcba9876543210
).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.Integer
if sufficiently
small, or a Long
if needed or if the L
suffix is
given; or a BigInteger
if the value is too large even for
long
; or null
if the string does not begin with the
numeric literal telltale of a 0-9 digit with optional minus.public static Number parseBinary(CharSequence s, Position pos)
0b010101000011
).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.Integer
if sufficiently
small, or a Long
if needed or if the L
suffix is
given; or a BigInteger
if the value is too large even for
long
; or null
if the string does not begin with the
numeric literal telltale of a 0-9 digit with optional minus.public static Number parseOctal(CharSequence s, Position pos)
01234567
).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.Integer
if sufficiently
small, or a Long
if needed or if the L
suffix is
given; or a BigInteger
if the value is too large even for
long
; or null
if the string does not begin with the
numeric literal telltale of a 0-9 digit with optional minus.public static Number parseDecimal(CharSequence s, Position pos)
1234.0987
or 1.2e34
).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.BigInteger
or BigDecimal
as
appropriate. Returns null if the string does not begin with the
numeric literal telltale of a 0-9 digit with optional minus.public static Number parseNumber(CharSequence s, Position pos)
This parsing mechanism is intended to be as close as possible to the numeric literals supported by the Java programming language itself.
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.BigInteger
or BigDecimal
as
appropriate. Returns null if the string does not begin with the
numeric literal telltale of a 0-9 digit with optional minus.public static Object parseLiteral(CharSequence s, Position pos)
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.Boolean
, String
or a concrete
Number
subclass. Returns null if the string does
not match the syntax of a known literal.parseBoolean(CharSequence, Position)
,
parseString(CharSequence, Position)
,
parseNumber(CharSequence, Position)
Copyright © 2015–2022 SciJava. All rights reserved.