1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2002-08-16 06:39:27 +00:00
parent 2229b70615
commit c27d662f50
2 changed files with 37 additions and 12 deletions

View file

@ -1,3 +1,7 @@
Fri Aug 16 15:37:04 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* bignum.c (rb_cstr_to_inum): new decimal and octal string.
Fri Aug 16 11:47:24 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* io.c (rb_io_fread): renamed from io_fread and made extern.

View file

@ -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')) {
str += 2;
}
else if (base == 2 && str[0] == '0' && (str[1] == 'b'||str[1] == 'B')) {
if (str[0] == '0' && (str[1] == 'o'||str[1] == 'O')) {
str += 2;
}
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');