summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-16 06:39:27 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-16 06:39:27 +0000
commitc27d662f503d101b26a3897436bb58e8a0253660 (patch)
tree40dc14496209fc3956d552ac3b5613a5eff78f36 /bignum.c
parent2229b70615ce502c567d6c27357ac2ccfa70eefd (diff)
downloadbundler-c27d662f503d101b26a3897436bb58e8a0253660.tar.gz
* bignum.c (rb_cstr_to_inum): new decimal and octal string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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');