From 99020d6e50702eb371111d73280eb80b4b29ba5b Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 25 Dec 2000 06:29:27 +0000 Subject: 001225 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'bignum.c') 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); } -- cgit v1.2.3