Package ch.randelshofer.fastdoubleparser
Class JsonDoubleParser
- java.lang.Object
-
- ch.randelshofer.fastdoubleparser.JsonDoubleParser
-
public final class JsonDoubleParser extends java.lang.ObjectParses adoublevalue; the supported syntax is compatible withnumberin 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:
numberwithout 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
-
-
Field Summary
Fields Modifier and Type Field Description private static JsonDoubleBitsFromByteArrayBYTE_ARRAY_PARSERprivate static JsonDoubleBitsFromCharArrayCHAR_ARRAY_PARSERprivate static JsonDoubleBitsFromCharSequenceCHAR_SEQUENCE_PARSER
-
Constructor Summary
Constructors Modifier Constructor Description privateJsonDoubleParser()Don't let anyone instantiate this class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doubleparseDouble(byte[] str)Convenience method for callingparseDouble(byte[], int, int).static doubleparseDouble(byte[] str, int offset, int length)Parses aFloatingPointLiteralfrom abyte-Array and converts it into adoublevalue.static doubleparseDouble(char[] str)Convenience method for callingparseDouble(char[], int, int).static doubleparseDouble(char[] str, int offset, int length)Parses aFloatingPointLiteralfrom abyte-Array and converts it into adoublevalue.static doubleparseDouble(java.lang.CharSequence str)Convenience method for callingparseDouble(CharSequence, int, int).static doubleparseDouble(java.lang.CharSequence str, int offset, int length)Parses aFloatingPointLiteralfrom aCharSequenceand converts it into adoublevalue.
-
-
-
Field Detail
-
BYTE_ARRAY_PARSER
private static final JsonDoubleBitsFromByteArray BYTE_ARRAY_PARSER
-
CHAR_ARRAY_PARSER
private static final JsonDoubleBitsFromCharArray CHAR_ARRAY_PARSER
-
CHAR_SEQUENCE_PARSER
private static final JsonDoubleBitsFromCharSequence CHAR_SEQUENCE_PARSER
-
-
Method Detail
-
parseDouble
public static double parseDouble(java.lang.CharSequence str) throws java.lang.NumberFormatExceptionConvenience method for callingparseDouble(CharSequence, int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseDouble
public static double parseDouble(java.lang.CharSequence str, int offset, int length) throws java.lang.NumberFormatExceptionParses aFloatingPointLiteralfrom aCharSequenceand converts it into adoublevalue.- Parameters:
str- the string to be parsedoffset- the start offset of theFloatingPointLiteralinstrlength- the length ofFloatingPointLiteralinstr- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseDouble
public static double parseDouble(byte[] str) throws java.lang.NumberFormatExceptionConvenience 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:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseDouble
public static double parseDouble(byte[] str, int offset, int length) throws java.lang.NumberFormatExceptionParses aFloatingPointLiteralfrom abyte-Array and converts it into adoublevalue.- 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:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseDouble
public static double parseDouble(char[] str) throws java.lang.NumberFormatExceptionConvenience method for callingparseDouble(char[], int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseDouble
public static double parseDouble(char[] str, int offset, int length) throws java.lang.NumberFormatExceptionParses aFloatingPointLiteralfrom abyte-Array and converts it into adoublevalue.See
JsonDoubleParserfor 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:
java.lang.NullPointerException- if the string is nulljava.lang.NumberFormatException- if the string can not be parsed successfully
-
-