use of java.util.regex.Pattern in project j2objc by google.
the class Scanner method nextBigInteger.
/**
* Returns the next token as a {@code BigInteger} with the specified radix.
* This method will block if input is being read. If the next token can be translated
* into a {@code BigInteger} the following is done: All {@code Locale}-specific
* prefixes, group separators, and {@code Locale}-specific suffixes are removed.
* Then non-ASCII digits are mapped into ASCII digits via
* {@link Character#digit(char, int)}, and a negative sign (-) is added if the
* {@code Locale}-specific negative prefix or suffix was present. Finally the
* resulting String is passed to {@link BigInteger#BigInteger(String, int)}}
* with the specified radix.
*
* @param radix
* the radix used to translate the token into a
* {@code BigInteger}.
* @return the next token as a {@code BigInteger}
* @throws IllegalStateException
* if this {@code Scanner} has been closed.
* @throws NoSuchElementException
* if input has been exhausted.
* @throws InputMismatchException
* if the next token can not be translated into a valid
* {@code BigInteger}.
*/
public BigInteger nextBigInteger(int radix) {
checkOpen();
Object obj = cachedNextValue;
cachedNextValue = null;
if (obj instanceof BigInteger) {
findStartIndex = cachedNextIndex;
return (BigInteger) obj;
}
Pattern integerPattern = getIntegerPattern(radix);
String intString = next(integerPattern);
intString = removeLocaleInfo(intString, int.class);
BigInteger bigIntegerValue;
try {
bigIntegerValue = new BigInteger(intString, radix);
} catch (NumberFormatException e) {
matchSuccessful = false;
recoverPreviousStatus();
throw new InputMismatchException();
}
return bigIntegerValue;
}
use of java.util.regex.Pattern in project j2objc by google.
the class Scanner method nextShort.
/**
* Returns the next token as a {@code short} with the specified radix. This method will
* block if input is being read. If the next token can be translated into a
* {@code short} the following is done: All {@code Locale}-specific prefixes, group
* separators, and {@code Locale}-specific suffixes are removed. Then non-ASCII
* digits are mapped into ASCII digits via
* {@link Character#digit(char, int)}, and a negative sign (-) is added if the
* {@code Locale}-specific negative prefix or suffix was present. Finally the
* resulting String is passed to {@link Short#parseShort(String, int)}}
* with the specified radix.
*
* @param radix
* the radix used to translate the token into {@code short}
* value.
* @return the next token as a {@code short}.
* @throws IllegalStateException
* if this {@code Scanner} has been closed.
* @throws NoSuchElementException
* if input has been exhausted.
* @throws InputMismatchException
* if the next token can not be translated into a valid
* {@code short} value.
*/
@SuppressWarnings("boxing")
public short nextShort(int radix) {
checkOpen();
Object obj = cachedNextValue;
cachedNextValue = null;
if (obj instanceof Short) {
findStartIndex = cachedNextIndex;
return (Short) obj;
}
Pattern integerPattern = getIntegerPattern(radix);
String intString = next(integerPattern);
intString = removeLocaleInfo(intString, int.class);
short shortValue;
try {
shortValue = Short.parseShort(intString, radix);
} catch (NumberFormatException e) {
matchSuccessful = false;
recoverPreviousStatus();
throw new InputMismatchException();
}
return shortValue;
}
use of java.util.regex.Pattern in project j2objc by google.
the class Scanner method nextBigDecimal.
/**
* Returns the next token as a {@code BigDecimal}. This method will block if input is
* being read. If the next token can be translated into a {@code BigDecimal}
* the following is done: All {@code Locale}-specific prefixes, group separators,
* and {@code Locale}-specific suffixes are removed. Then non-ASCII digits are
* mapped into ASCII digits via {@link Character#digit(char, int)}, and a
* negative sign (-) is added if the {@code Locale}-specific negative prefix or
* suffix was present. Finally the resulting string is passed to
* {@code BigDecimal(String) }.
*
* @return the next token as a {@code BigDecimal}.
* @throws IllegalStateException
* if this {@code Scanner} has been closed.
* @throws NoSuchElementException
* if input has been exhausted.
* @throws InputMismatchException
* if the next token can not be translated into a valid
* {@code BigDecimal}.
*/
public BigDecimal nextBigDecimal() {
checkOpen();
Object obj = cachedNextValue;
cachedNextValue = null;
if (obj instanceof BigDecimal) {
findStartIndex = cachedNextIndex;
return (BigDecimal) obj;
}
Pattern floatPattern = getFloatPattern();
String floatString = next(floatPattern);
floatString = removeLocaleInfoFromFloat(floatString);
BigDecimal bigDecimalValue;
try {
bigDecimalValue = new BigDecimal(floatString);
} catch (NumberFormatException e) {
matchSuccessful = false;
recoverPreviousStatus();
throw new InputMismatchException();
}
return bigDecimalValue;
}
use of java.util.regex.Pattern in project j2objc by google.
the class Scanner method hasNextByte.
/**
* Returns whether the next token can be translated into a valid
* {@code byte} value in the specified radix.
*
* @param radix
* the radix used to translate the token into a {@code byte}
* value
* @return {@code true} if the next token can be translated into a valid
* {@code byte} value, otherwise {@code false}.
* @throws IllegalStateException
* if the {@code Scanner} has been closed.
*/
public boolean hasNextByte(int radix) {
Pattern integerPattern = getIntegerPattern(radix);
boolean isByteValue = false;
if (hasNext(integerPattern)) {
String intString = matcher.group();
intString = removeLocaleInfo(intString, int.class);
try {
cachedNextValue = Byte.valueOf(intString, radix);
isByteValue = true;
} catch (NumberFormatException e) {
matchSuccessful = false;
}
}
return isByteValue;
}
use of java.util.regex.Pattern in project j2objc by google.
the class Scanner method nextInt.
/**
* Returns the next token as an {@code int} with the specified radix. This method will
* block if input is being read. If the next token can be translated into an
* {@code int} the following is done: All {@code Locale}-specific prefixes, group
* separators, and {@code Locale}-specific suffixes are removed. Then non-ASCII
* digits are mapped into ASCII digits via
* {@link Character#digit(char, int)}, and a negative sign (-) is added if the
* {@code Locale}-specific negative prefix or suffix was present. Finally the
* resulting String is passed to {@link Integer#parseInt(String, int)} with
* the specified radix.
*
* @param radix
* the radix used to translate the token into an {@code int}
* value.
* @return the next token as an {@code int}.
* @throws IllegalStateException
* if this {@code Scanner} has been closed.
* @throws NoSuchElementException
* if input has been exhausted.
* @throws InputMismatchException
* if the next token can not be translated into a valid
* {@code int} value.
*/
@SuppressWarnings("boxing")
public int nextInt(int radix) {
checkOpen();
Object obj = cachedNextValue;
cachedNextValue = null;
if (obj instanceof Integer) {
findStartIndex = cachedNextIndex;
return (Integer) obj;
}
Pattern integerPattern = getIntegerPattern(radix);
String intString = next(integerPattern);
intString = removeLocaleInfo(intString, int.class);
int intValue;
try {
intValue = Integer.parseInt(intString, radix);
} catch (NumberFormatException e) {
matchSuccessful = false;
recoverPreviousStatus();
throw new InputMismatchException();
}
return intValue;
}
Aggregations