Class JsonDoubleParser

java.lang.Object
ch.randelshofer.fastdoubleparser.JsonDoubleParser

public class JsonDoubleParser extends Object
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.
References:
IETF RFC 8259. The JavaScript Object Notation (JSON) Data Interchange Format, Chapter 6. Numbers
www.ietf.org
  • Method Details

    • parseDouble

      public static double parseDouble(CharSequence str) throws NumberFormatException
      Convenience method for calling parseDouble(CharSequence, int, int).
      Parameters:
      str - the string to be parsed
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully
    • parseDouble

      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 - the string to be parsed
      offset - the start offset of the FloatingPointLiteral in str
      length - the length of FloatingPointLiteral in str
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseDouble

      public static double parseDouble(byte[] str) throws NumberFormatException
      Convenience method for calling parseDouble(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 null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseDouble

      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 - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
      offset - The index of the first byte to parse
      length - The number of bytes to parse
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseDouble

      public static double parseDouble(char[] str) throws NumberFormatException
      Convenience method for calling parseDouble(char[], int, int).
      Parameters:
      str - the string to be parsed
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully
    • parseDouble

      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 JsonDoubleParser for the syntax of FloatingPointLiteral.

      Parameters:
      str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
      offset - The index of the first character to parse
      length - The number of characters to parse
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully