mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -04:00
improved the number parser
This commit is contained in:
parent
2c311f6e70
commit
02e700f463
@ -158,31 +158,32 @@ public final class Bits {
|
||||
return 0;
|
||||
|
||||
int radix;
|
||||
switch (str.charAt(p)) {
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (wasZero) {
|
||||
if (neg) throw new NumberFormatException(str, p);
|
||||
switch (str.charAt(p)) {
|
||||
case 'x':
|
||||
case 'X':
|
||||
radix = 16;
|
||||
p++;
|
||||
if (p == str.length()) throw new NumberFormatException(str, p);
|
||||
break;
|
||||
case 'b':
|
||||
case 'B':
|
||||
radix = 2;
|
||||
p++;
|
||||
if (p == str.length()) throw new NumberFormatException(str, p);
|
||||
break;
|
||||
default:
|
||||
radix = 8;
|
||||
}
|
||||
} else {
|
||||
if (str.charAt(p) == '\'') {
|
||||
if (neg) throw new NumberFormatException(str, p);
|
||||
radix = 16;
|
||||
p++;
|
||||
if (p == str.length()) throw new NumberFormatException(str, p);
|
||||
break;
|
||||
case 'b':
|
||||
case 'B':
|
||||
if (neg) throw new NumberFormatException(str, p);
|
||||
radix = 2;
|
||||
p++;
|
||||
if (p == str.length()) throw new NumberFormatException(str, p);
|
||||
break;
|
||||
case '\'':
|
||||
p++;
|
||||
if (p == str.length()) throw new NumberFormatException(str, p);
|
||||
return str.charAt(p);
|
||||
default:
|
||||
if (wasZero) {
|
||||
if (neg) throw new NumberFormatException(str, p);
|
||||
radix = 8;
|
||||
} else
|
||||
radix = 10;
|
||||
} else
|
||||
radix = 10;
|
||||
}
|
||||
|
||||
long val = decode(str, p, radix);
|
||||
|
Loading…
x
Reference in New Issue
Block a user