Package ch.randelshofer.fastdoubleparser
Class JsonDoubleParser
java.lang.Object
ch.randelshofer.fastdoubleparser.JsonDoubleParser
Parses a
double
value; the supported syntax is compatible with
number
in the JSON format specification.
Syntax
Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.
number = [ minus ] int [ frac ] [ exp ] minus = %x2D ; - int = zero / ( digit1-9 *DIGIT ) frac = decimal-point 1*DIGIT exp = e [ minus / plus ] 1*DIGIT decimal-point = %x2E ; . digit1-9 = %x31-39 ; 1-9 e = %x65 / %x45 ; e E plus = %x2B ; + zero = %x30 ; 0
Supported maximal input length:
number
without white space around it:Integer.MAX_VALUE
- 4 = 2,147,483,643 characters.
- IETF RFC 8259. The JavaScript Object Notation (JSON) Data Interchange Format, Chapter 6. Numbers
- www.ietf.org
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
parseDouble
(byte[] str) Convenience method for callingparseDouble(byte[], int, int)
.static double
parseDouble
(byte[] str, int offset, int length) Parses aFloatingPointLiteral
from abyte
-Array and converts it into adouble
value.static double
parseDouble
(char[] str) Convenience method for callingparseDouble(char[], int, int)
.static double
parseDouble
(char[] str, int offset, int length) Parses aFloatingPointLiteral
from abyte
-Array and converts it into adouble
value.static double
parseDouble
(CharSequence str) Convenience method for callingparseDouble(CharSequence, int, int)
.static double
parseDouble
(CharSequence str, int offset, int length)
-
Method Details
-
parseDouble
Convenience method for callingparseDouble(CharSequence, int, int)
.- Parameters:
str
- the string to be parsed- Returns:
- the parsed value
- Throws:
NullPointerException
- if the string is nullNumberFormatException
- if the string can not be parsed successfully
-
parseDouble
public static double parseDouble(CharSequence str, int offset, int length) throws NumberFormatException - Parameters:
str
- the string to be parsedoffset
- the start offset of theFloatingPointLiteral
instr
length
- the length ofFloatingPointLiteral
instr
- Returns:
- the parsed value
- Throws:
NullPointerException
- if the string is nullIllegalArgumentException
- if offset or length are illegalNumberFormatException
- if the string can not be parsed successfully
-
parseDouble
Convenience method for callingparseDouble(byte[], int, int)
.- Parameters:
str
- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding- Returns:
- the parsed value
- Throws:
NullPointerException
- if the string is nullIllegalArgumentException
- if offset or length are illegalNumberFormatException
- if the string can not be parsed successfully
-
parseDouble
Parses aFloatingPointLiteral
from abyte
-Array and converts it into adouble
value.- Parameters:
str
- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset
- The index of the first byte to parselength
- The number of bytes to parse- Returns:
- the parsed value
- Throws:
NullPointerException
- if the string is nullIllegalArgumentException
- if offset or length are illegalNumberFormatException
- if the string can not be parsed successfully
-
parseDouble
Convenience method for callingparseDouble(char[], int, int)
.- Parameters:
str
- the string to be parsed- Returns:
- the parsed value
- Throws:
NullPointerException
- if the string is nullNumberFormatException
- if the string can not be parsed successfully
-
parseDouble
Parses aFloatingPointLiteral
from abyte
-Array and converts it into adouble
value.See
JsonDoubleParser
for the syntax ofFloatingPointLiteral
.- Parameters:
str
- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset
- The index of the first character to parselength
- The number of characters to parse- Returns:
- the parsed value
- Throws:
NullPointerException
- if the string is nullNumberFormatException
- if the string can not be parsed successfully
-