String#to_i e$B$,@5$7$/5!G=$7$J$$$3$H$,$"$j$^$9!#e(Bruby
e$B<+?H$N;z6g2r<a$H$be(B
e$B0c$$$^$9!#$?$V$s!"e(B1.8 e$B$bF1$8$G$9!#e(B
$ ./ruby -v -e ‘p “0_2”.to_i’
ruby 1.9.0 (2008-01-29 revision 0) [i386-freebsd6.2]
0
e$B$3$s$J46$8$G$7$g$&$+!#e(B
Index: bignum.c
— bignum.c (revision 15328)
+++ bignum.c (working copy)
@@ -438,7 +438,7 @@
len = 2;
break;
case 8:
- if (str[0] == ‘0’ && (str[1] == ‘o’||str[1] == ‘O’||str[1] == ‘_’)) {
- if (str[0] == ‘0’ && (str[1] == ‘o’||str[1] == ‘O’)) {
str += 2;
}
case 4: case 5: case 6: case 7:
@@ -470,7 +470,7 @@
break;
}
if (str == ‘0’) { / squeeze preceding 0s */
- while (*++str == ‘0’);
- while (*++str == ‘0’ || *str == ‘_’);
if (!(c = *str) || ISSPACE©) --str;
}
c = *str;
Index: test/ruby/test_bignum.rb
===================================================================
— test/ruby/test_bignum.rb (revision 15328)
+++ test/ruby/test_bignum.rb (working copy)
@@ -147,6 +147,9 @@
assert_raise(ArgumentError) { Integer(“1__”) }
assert_raise(ArgumentError) { Integer(“1_0 x”) }
assert_equal(T31P, “1111111111111111111111111111111”.to_i(2)) - assert_equal(0_2, ‘0_2’.to_i)
- assert_equal(00_2, ‘00_2’.to_i)
- assert_equal(00_02, ‘00_02’.to_i)
end
def test_to_s2