Package ch.randelshofer.fastdoubleparser
Class JavaFloatParser
- java.lang.Object
-
- ch.randelshofer.fastdoubleparser.JavaFloatParser
-
public final class JavaFloatParser extends java.lang.ObjectParses afloatvalue; the supported syntax is compatible withFloat.valueOf(String).See
JavaDoubleParserfor a description of the supported grammar.Expected character lengths for values produced by
Float.toString(float):DecSignificand(IntegerPart+FractionPart): 1 to 8 digitsIntegerPart: 1 to 7 digitsFractionPart: 1 to 7 digitsSignedIntegerin exponent: 1 to 2 digitsFloatingPointLiteral: 1 to 14 characters, e.g. "-1.2345678E-38"
FloatingPointLiteralwith or without white space around it:Integer.MAX_VALUE- 4 = 2,147,483,643 characters.
-
-
Field Summary
Fields Modifier and Type Field Description private static JavaFloatBitsFromByteArrayBYTE_ARRAY_PARSERprivate static JavaFloatBitsFromCharArrayCHAR_ARRAY_PARSERprivate static JavaFloatBitsFromCharSequenceCHAR_SEQUENCE_PARSER
-
Constructor Summary
Constructors Modifier Constructor Description privateJavaFloatParser()Don't let anyone instantiate this class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static floatparseFloat(byte[] str)Convenience method for callingparseFloat(byte[], int, int).static floatparseFloat(byte[] str, int offset, int length)Parses aFloatingPointLiteralfrom abyte-Array and converts it into afloatvalue.static floatparseFloat(char[] str)Convenience method for callingparseFloat(char[], int, int).static floatparseFloat(char[] str, int offset, int length)Parses aFloatingPointLiteralfrom abyte-Array and converts it into afloatvalue.static floatparseFloat(java.lang.CharSequence str)Convenience method for callingparseFloat(CharSequence, int, int).static floatparseFloat(java.lang.CharSequence str, int offset, int length)Parses aFloatingPointLiteralfrom aCharSequenceand converts it into afloatvalue.
-
-
-
Field Detail
-
BYTE_ARRAY_PARSER
private static final JavaFloatBitsFromByteArray BYTE_ARRAY_PARSER
-
CHAR_ARRAY_PARSER
private static final JavaFloatBitsFromCharArray CHAR_ARRAY_PARSER
-
CHAR_SEQUENCE_PARSER
private static final JavaFloatBitsFromCharSequence CHAR_SEQUENCE_PARSER
-
-
Method Detail
-
parseFloat
public static float parseFloat(java.lang.CharSequence str) throws java.lang.NumberFormatExceptionConvenience method for callingparseFloat(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
-
parseFloat
public static float parseFloat(java.lang.CharSequence str, int offset, int length) throws java.lang.NumberFormatExceptionParses aFloatingPointLiteralfrom aCharSequenceand converts it into afloatvalue.- 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
-
parseFloat
public static float parseFloat(byte[] str) throws java.lang.NumberFormatExceptionConvenience method for callingparseFloat(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.NumberFormatException- if the string can not be parsed successfully
-
parseFloat
public static float parseFloat(byte[] str, int offset, int length) throws java.lang.NumberFormatExceptionParses aFloatingPointLiteralfrom abyte-Array and converts it into afloatvalue.- 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
-
parseFloat
public static float parseFloat(char[] str) throws java.lang.NumberFormatExceptionConvenience method for callingparseFloat(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
-
parseFloat
public static float parseFloat(char[] str, int offset, int length) throws java.lang.NumberFormatExceptionParses aFloatingPointLiteralfrom abyte-Array and converts it into afloatvalue.- 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.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
-