718 |
int len = str.length(); |
int len = str.length(); |
719 |
boolean isNeg = false; |
boolean isNeg = false; |
720 |
if (len == 0) |
if (len == 0) |
721 |
throw new NumberFormatException(); |
throw new NumberFormatException("string length is null"); |
722 |
int ch = str.charAt(index); |
int ch = str.charAt(index); |
723 |
if (ch == '-') |
if (ch == '-') |
724 |
{ |
{ |
725 |
if (len == 1) |
if (len == 1) |
726 |
throw new NumberFormatException(); |
throw new NumberFormatException("pure '-'"); |
727 |
isNeg = true; |
isNeg = true; |
728 |
ch = str.charAt(++index); |
ch = str.charAt(++index); |
729 |
} |
} |
748 |
} |
} |
749 |
} |
} |
750 |
if (index == len) |
if (index == len) |
751 |
throw new NumberFormatException(); |
throw new NumberFormatException("non terminated number: " + str); |
752 |
|
|
753 |
int max = MAX_VALUE / radix; |
int max = MAX_VALUE / radix; |
754 |
// We can't directly write `max = (MAX_VALUE + 1) / radix'. |
// We can't directly write `max = (MAX_VALUE + 1) / radix'. |
760 |
while (index < len) |
while (index < len) |
761 |
{ |
{ |
762 |
if (val < 0 || val > max) |
if (val < 0 || val > max) |
763 |
throw new NumberFormatException(); |
throw new NumberFormatException("number overflow (pos=" + index + ") : " + str); |
764 |
|
|
765 |
ch = Character.digit(str.charAt(index++), radix); |
ch = Character.digit(str.charAt(index++), radix); |
766 |
val = val * radix + ch; |
val = val * radix + ch; |
767 |
if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE))) |
if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE))) |
768 |
throw new NumberFormatException(); |
throw new NumberFormatException("invalid character at position " + index + " in " + str); |
769 |
} |
} |
770 |
return isNeg ? -val : val; |
return isNeg ? -val : val; |
771 |
} |
} |