Package ch.randelshofer.fastdoubleparser
Class JavaBigIntegerParser
java.lang.Object
ch.randelshofer.fastdoubleparser.JavaBigIntegerParser
Parses a
BigInteger
value; the supported syntax is compatible
with BigInteger(String, int)
.
Syntax
Formal specification of the grammar:
- BigIntegerLiteral:
- [Sign] Digits
- Sign:
- (one of)
+ -
- Digits:
- Digit {Digit}
- Digit:
- (one of)
0 1 2 3 4 5 6 7 8 9
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Character lengths accepted by BigInteger(String)
:
Significand
: 1 to 1,292,782,621 decimal digits.The resulting value must fit into
2^31 - 1
bits. The decimal representation of the value2^31 - 1
has 646,456,993 digits. Therefore an input String can only contain up to that many significant digits - the remaining digits must be leading zeroes.
BigIntegerLiteral
: 1,292,782,621 + 1 = 1,292,782,622 characters.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BigInteger
parseBigInteger
(byte[] str) Convenience method for callingparseBigInteger(byte[], int, int)
.static BigInteger
parseBigInteger
(byte[] str, int radix) Convenience method for callingparseBigInteger(byte[], int, int, int)
.static BigInteger
parseBigInteger
(byte[] str, int offset, int length) static BigInteger
parseBigInteger
(byte[] str, int offset, int length, int radix) static BigInteger
parseBigInteger
(char[] str) Convenience method for callingparseBigInteger(char[], int, int)
.static BigInteger
parseBigInteger
(char[] str, int radix) Convenience method for callingparseBigInteger(char[], int, int, int)
.static BigInteger
parseBigInteger
(char[] str, int offset, int length) static BigInteger
parseBigInteger
(char[] str, int offset, int length, int radix) static BigInteger
Convenience method for callingparseBigInteger(CharSequence, int, int)
.static BigInteger
parseBigInteger
(CharSequence str, int radix) Convenience method for callingparseBigInteger(CharSequence, int, int, int)
.static BigInteger
parseBigInteger
(CharSequence str, int offset, int length) Convenience method for callingparseBigInteger(CharSequence, int, int, int)
.static BigInteger
parseBigInteger
(CharSequence str, int offset, int length, int radix)
-
Method Details
-
parseBigInteger
Convenience method for callingparseBigInteger(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
-
parseBigInteger
Convenience method for callingparseBigInteger(CharSequence, int, int, int)
.- Parameters:
str
- the string to be parsedradix
- the radix to be used in interpreting thestr
- Returns:
- the parsed value
- Throws:
NullPointerException
- if the string is nullNumberFormatException
- if the string can not be parsed successfully
-
parseBigInteger
Convenience method for callingparseBigInteger(CharSequence, int, int, int)
.- Parameters:
str
- the string to be parsedoffset
- The index of the first character to parselength
- The number of characters 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
-
parseBigInteger
- Parameters:
str
- the string to be parsedoffset
- The index of the first character to parselength
- The number of characters to parseradix
- the radix to be used in interpreting thestr
- 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
-
parseBigInteger
Convenience method for callingparseBigInteger(byte[], 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
-
parseBigInteger
Convenience method for callingparseBigInteger(byte[], int, int, int)
.- Parameters:
str
- the string to be parsedradix
- the radix to be used in interpreting thestr
- Returns:
- the parsed value
- Throws:
NullPointerException
- if the string is nullNumberFormatException
- if the string can not be parsed successfully
-
parseBigInteger
Parses aBigIntegerLiteral
from abyte
-Array and converts it into aBigInteger
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 nullIllegalArgumentException
- if offset or length are illegalNumberFormatException
- if the string can not be parsed successfully
-
parseBigInteger
Parses aBigIntegerLiteral
from abyte
-Array and converts it into aBigInteger
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 parseradix
- the radix to be used in interpreting thestr
- 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
-
parseBigInteger
Convenience method for callingparseBigInteger(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
-
parseBigInteger
Convenience method for callingparseBigInteger(char[], int, int, int)
.- Parameters:
str
- the string to be parsedradix
- the radix to be used in interpreting thestr
- Returns:
- the parsed value
- Throws:
NullPointerException
- if the string is nullNumberFormatException
- if the string can not be parsed successfully
-
parseBigInteger
Parses aBigIntegerLiteral
from achar
-Array and converts it into aBigInteger
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 nullIllegalArgumentException
- if offset or length are illegalNumberFormatException
- if the string can not be parsed successfully
-
parseBigInteger
Parses aBigIntegerLiteral
from achar
-Array and converts it into aBigInteger
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 parseradix
- the radix to be used in interpreting thestr
- 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
-