Class JsonDoubleParser


  • public final class JsonDoubleParser
    extends java.lang.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
    • Constructor Detail

      • JsonDoubleParser

        private JsonDoubleParser()
        Don't let anyone instantiate this class.
    • Method Detail

      • parseDouble

        public static double parseDouble​(java.lang.CharSequence str)
                                  throws java.lang.NumberFormatException
        Convenience method for calling parseDouble(CharSequence, int, int).
        Parameters:
        str - the string to be parsed
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.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.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:
        java.lang.NullPointerException - if the string is null
        java.lang.IllegalArgumentException - if offset or length are illegal
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseDouble

        public static double parseDouble​(byte[] str)
                                  throws java.lang.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:
        java.lang.NullPointerException - if the string is null
        java.lang.IllegalArgumentException - if offset or length are illegal
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseDouble

        public static double parseDouble​(byte[] str,
                                         int offset,
                                         int length)
                                  throws java.lang.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:
        java.lang.NullPointerException - if the string is null
        java.lang.IllegalArgumentException - if offset or length are illegal
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseDouble

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

        public static double parseDouble​(char[] str,
                                         int offset,
                                         int length)
                                  throws java.lang.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:
        java.lang.NullPointerException - if the string is null
        java.lang.NumberFormatException - if the string can not be parsed successfully