summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-12-25 06:29:27 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-12-25 06:29:27 +0000
commit99020d6e50702eb371111d73280eb80b4b29ba5b (patch)
treef2ec985d66f5d99a203277cf0961d960228d441e /bignum.c
parent8f6673c2d4a7e6ff470b584141c590e4b066f5e2 (diff)
001225
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/bignum.c b/bignum.c
index 1e847dd7af..daf131b042 100644
--- a/bignum.c
+++ b/bignum.c
@@ -219,12 +219,8 @@ rb_cstr2inum(str, base)
}
else {
base = 8;
- if (!str[1]) return INT2FIX(0);
}
}
- else if (str[0] == 0) {
- return INT2FIX(0);
- }
else {
base = 10;
}
@@ -256,7 +252,7 @@ rb_cstr2inum(str, base)
while (*end && ISSPACE(*end)) end++;
if (*end) { /* trailing garbage */
bad:
- rb_raise(rb_eArgError, "invalid literal for Integer: %s", s);
+ rb_raise(rb_eArgError, "invalid value for Integer: \"%s\"", s);
}
}
@@ -282,28 +278,28 @@ rb_cstr2inum(str, base)
for (i=len;i--;) zds[i]=0;
while (c = *str++) {
switch (c) {
+ case '8': case '9':
+ if (base == 8) {
+ c = base;
+ break;
+ }
case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
+ case '5': case '6': case '7':
c = c - '0';
break;
case 'a': case 'b': case 'c':
case 'd': case 'e': case 'f':
- c = c - 'a' + 10;
+ if (base != 16) c = base;
+ else c = c - 'a' + 10;
break;
case 'A': case 'B': case 'C':
case 'D': case 'E': case 'F':
- c = c - 'A' + 10;
+ if (base != 16) c = base;
+ else c = c - 'A' + 10;
break;
case '_':
continue;
default:
- if (badcheck) {
- if (ISSPACE(c)) {
- while (*str && ISSPACE(*str)) str++;
- if (!*str) break;
- }
- rb_raise(rb_eArgError, "invalid literal for Integer: %s", s);
- }
c = base;
break;
}
@@ -323,7 +319,14 @@ rb_cstr2inum(str, base)
break;
}
}
- if (badcheck && s+2 < str && str[-2] == '_') goto bad;
+ if (badcheck) {
+ str--;
+ if (s+1 < str && str[-1] == '_') goto bad;
+ if (ISSPACE(c)) {
+ while (*str && ISSPACE(*str)) str++;
+ }
+ if (*str) goto bad;
+ }
return bignorm(z);
}