Top Description Fields Constructors Methods
ch.randelshofer.fastdoubleparser

public Class JavaDoubleParser

extends Object
Class Inheritance

Parses a double value; the supported syntax is compatible with Double#valueOf(String).

Syntax

Leading and trailing whitespace characters in str are ignored. Whitespace is removed as if by the java.lang.String#trim() method; that is, characters in the range [U+0000,U+0020].

The rest of str should constitute a Java FloatingPointLiteral as described by the lexical syntax rules shown below:

FloatingPointLiteral:
[Sign] NaN
[Sign] Infinity
[Sign] DecimalFloatingPointLiteral
[Sign] HexFloatingPointLiteral
SignedInteger
HexFloatingPointLiteral:
HexSignificand BinaryExponent [FloatTypeSuffix]
HexSignificand:
HexNumeral
HexNumeral .
0x [HexDigits] . HexDigits
0X [HexDigits] . HexDigits
BinaryExponent:
BinaryExponentIndicator SignedInteger
BinaryExponentIndicator:
p
P
DecimalFloatingPointLiteral:
DecSignificand [DecExponent] [FloatTypeSuffix]
DecSignificand:
IntegerPart . [FractionPart]
. FractionPart
IntegerPart
IntegerPart:
Digits
FractionPart:
Digits
DecExponent:
ExponentIndicator SignedInteger
ExponentIndicator:
e
E
SignedInteger:
[Sign] Digits
Sign:
+
-
Digits:
Digit {Digit}
Digit:
(one of)
0 1 2 3 4 5 6 7 8 9
HexNumeral:
0 x HexDigits
0 X HexDigits
HexDigits:
HexDigit {HexDigit}
HexDigit:
(one of)
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
FloatTypeSuffix:
(one of)
f F d D

Expected character lengths for values produced by Double#toString:

Maximal input length supported by this parser:

References:

The Java® Language Specification, Java SE 18 Edition, Chapter 3. Lexical Structure, 3.10.2. Floating-Point Literals
docs.oracle.com

Field Summary

Modifier and TypeField and Description
private static final JavaDoubleBitsFromByteArray
private static final JavaDoubleBitsFromCharArray
private static final JavaDoubleBitsFromCharSequence

Constructor Summary

AccessConstructor and Description
private
JavaDoubleParser()

Don't let anyone instantiate this class.

Method Summary

Modifier and TypeMethod and Description
public static double

Returns:

the parsed value
parseDouble
(CharSequence
the string to be parsed
str
)

Convenience method for calling parseDouble(CharSequence, int, int).

public static double

Returns:

the parsed value
parseDouble
(CharSequence
the string to be parsed
str
,
int
the start offset of the FloatingPointLiteral in str
offset
,
int
the length of FloatingPointLiteral in str
length
)

Parses a FloatingPointLiteral from a CharSequence and converts it into a double value.

public static double

Returns:

the parsed value
parseDouble
(byte[]
the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
str
)

Convenience method for calling parseDouble(byte[], int, int).

public static double

Returns:

the parsed value
parseDouble
(byte[]
the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
str
,
int
The index of the first byte to parse
offset
,
int
The number of bytes to parse
length
)

Parses a FloatingPointLiteral from a byte-Array and converts it into a double value.

public static double

Returns:

the parsed value
parseDouble
(char[]
the string to be parsed
str
)

Convenience method for calling parseDouble(char[], int, int).

public static double

Returns:

the parsed value
parseDouble
(char[]
the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
str
,
int
The index of the first character to parse
offset
,
int
The number of characters to parse
length
)

Parses a FloatingPointLiteral from a byte-Array and converts it into a double value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTE_ARRAY_PARSERback to summary
private static final JavaDoubleBitsFromByteArray BYTE_ARRAY_PARSER
CHAR_ARRAY_PARSERback to summary
private static final JavaDoubleBitsFromCharArray CHAR_ARRAY_PARSER
CHAR_SEQUENCE_PARSERback to summary
private static final JavaDoubleBitsFromCharSequence CHAR_SEQUENCE_PARSER

Constructor Detail

JavaDoubleParserback to summary
private JavaDoubleParser()

Don't let anyone instantiate this class.

Method Detail

parseDoubleback to summary
public static double parseDouble(CharSequence str) throws NumberFormatException

Convenience method for calling parseDouble(CharSequence, int, int).

Parameters
str:CharSequence

the string to be parsed

Returns:double

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
parseDoubleback to summary
public static double parseDouble(CharSequence str, int offset, int length) throws NumberFormatException

Parses a FloatingPointLiteral from a CharSequence and converts it into a double value.

Parameters
str:CharSequence

the string to be parsed

offset:int

the start offset of the FloatingPointLiteral in str

length:int

the length of FloatingPointLiteral in str

Returns:double

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
IllegalArgumentException:
if offset or length are illegal
parseDoubleback to summary
public static double parseDouble(byte[] str) throws NumberFormatException

Convenience method for calling parseDouble(byte[], int, int).

Parameters
str:byte[]

the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding

Returns:double

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
IllegalArgumentException:
if offset or length are illegal
parseDoubleback to summary
public static double parseDouble(byte[] str, int offset, int length) throws NumberFormatException

Parses a FloatingPointLiteral from a byte-Array and converts it into a double value.

Parameters
str:byte[]

the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding

offset:int

The index of the first byte to parse

length:int

The number of bytes to parse

Returns:double

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
IllegalArgumentException:
if offset or length are illegal
parseDoubleback to summary
public static double parseDouble(char[] str) throws NumberFormatException

Convenience method for calling parseDouble(char[], int, int).

Parameters
str:char[]

the string to be parsed

Returns:double

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
parseDoubleback to summary
public static double parseDouble(char[] str, int offset, int length) throws NumberFormatException

Parses a FloatingPointLiteral from a byte-Array and converts it into a double value.

See JavaDoubleParser for the syntax of FloatingPointLiteral.

Parameters
str:char[]

the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding

offset:int

The index of the first character to parse

length:int

The number of characters to parse

Returns:double

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
IllegalArgumentException:
if offset or length are illegal