summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/bignum.c b/bignum.c
index 622fd5e1af..36092c8427 100644
--- a/bignum.c
+++ b/bignum.c
@@ -340,13 +340,20 @@ rb_cstr_to_inum(str, base, badcheck)
}
if (base <= 0) {
if (str[0] == '0') {
- if (str[1] == 'x' || str[1] == 'X') {
+ switch (str[1]) {
+ case 'x': case 'X':
base = 16;
- }
- else if (str[1] == 'b' || str[1] == 'B') {
+ break;
+ case 'b': case 'B':
base = 2;
- }
- else {
+ break;
+ case 'o': case 'O':
+ base = 8;
+ break;
+ case 'd': case 'D':
+ base = 10;
+ break;
+ default:
base = 8;
}
}
@@ -357,17 +364,31 @@ rb_cstr_to_inum(str, base, badcheck)
base = 10;
}
}
- if (base == 8) {
+ switch (base) {
+ case 2:
+ len = 1;
+ if (str[0] == '0' && (str[1] == 'b'||str[1] == 'B')) {
+ str += 2;
+ }
+ break;
+ case 8:
len = 3;
- }
- else { /* base == 10, 2 or 16 */
- if (base == 16 && str[0] == '0' && (str[1] == 'x'||str[1] == 'X')) {
+ if (str[0] == '0' && (str[1] == 'o'||str[1] == 'O')) {
str += 2;
}
- else if (base == 2 && str[0] == '0' && (str[1] == 'b'||str[1] == 'B')) {
+ break;
+ case 10:
+ len = 4;
+ if (str[0] == '0' && (str[1] == 'd'||str[1] == 'D')) {
str += 2;
}
+ break;
+ case 16:
len = 4;
+ if (str[0] == '0' && (str[1] == 'x'||str[1] == 'X')) {
+ str += 2;
+ }
+ break;
}
if (*str == '0') { /* squeeze preceeding 0s */
while (*++str == '0');