mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -04:00
refactor: decompose condition of digit checks by using extra method 'isNumericChar(...)' in NumberConversionUtil.
This commit is contained in:
parent
75419e3f25
commit
7f1cb8bf62
@ -24,7 +24,7 @@ class NumberConversionUtil {
|
||||
val = "-0."+val.substring(2);
|
||||
}
|
||||
char initial = val.charAt(0);
|
||||
if ((initial >= '0' && initial <= '9') || initial == '-' ) {
|
||||
if ( isNumericChar(initial) || initial == '-' ) {
|
||||
// decimal representation
|
||||
if (isDecimalNotation(val)) {
|
||||
// Use a BigDecimal all the time so we keep the original
|
||||
@ -53,13 +53,13 @@ class NumberConversionUtil {
|
||||
initial = val.charAt(0);
|
||||
if(initial == '0' && val.length() > 1) {
|
||||
char at1 = val.charAt(1);
|
||||
if(at1 >= '0' && at1 <= '9') {
|
||||
if(isNumericChar(at1)) {
|
||||
throw new NumberFormatException("val ["+input+"] is not a valid number.");
|
||||
}
|
||||
} else if (initial == '-' && val.length() > 2) {
|
||||
char at1 = val.charAt(1);
|
||||
char at2 = val.charAt(2);
|
||||
if(at1 == '0' && at2 >= '0' && at2 <= '9') {
|
||||
if(at1 == '0' && isNumericChar(at2)) {
|
||||
throw new NumberFormatException("val ["+input+"] is not a valid number.");
|
||||
}
|
||||
}
|
||||
@ -83,6 +83,16 @@ class NumberConversionUtil {
|
||||
throw new NumberFormatException("val ["+input+"] is not a valid number.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the character is a numeric digit ('0' to '9').
|
||||
*
|
||||
* @param c The character to be checked.
|
||||
* @return true if the character is a numeric digit, false otherwise.
|
||||
*/
|
||||
private static boolean isNumericChar(char c) {
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the value could be considered a number in decimal number system.
|
||||
* @param value
|
||||
|
Loading…
x
Reference in New Issue
Block a user