diff --git a/ChangeLog b/ChangeLog index 3060787ead..0f32a33b2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jul 8 00:22:58 2008 Nobuyoshi Nakada + + * string.c (rb_str_succ): limit carrying in an alphanumeric region if + exists. [ruby-dev:35094] + Mon Jul 7 20:39:28 2008 Masaki Suketa * ext/win32ole/win32ole.c(Init_win32ole): add diff --git a/string.c b/string.c index 983f3e682a..8c1cf0d831 100644 --- a/string.c +++ b/string.c @@ -2535,13 +2535,16 @@ rb_str_succ(VALUE orig) enum neighbor_char neighbor; if ((l = rb_enc_precise_mbclen(s, e, enc)) <= 0) continue; neighbor = enc_succ_alnum_char(s, l, enc, carry); - if (neighbor == NEIGHBOR_NOT_CHAR) - continue; - if (neighbor == NEIGHBOR_FOUND) + if (neighbor == NEIGHBOR_NOT_CHAR) { + if (c == -1) continue; + s++; + } + else if (neighbor == NEIGHBOR_FOUND) return str; c = 1; carry_pos = s - sbeg; carry_len = l; + if (neighbor == NEIGHBOR_NOT_CHAR) break; } if (c == -1) { /* str contains no alnum */ s = e; diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 869e31b641..29bc2672ec 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1222,6 +1222,7 @@ class TestString < Test::Unit::TestCase assert_equal(S("124"), S("123").succ) assert_equal(S("1000"), S("999").succ) + assert_equal(S("No.10"), S("No.9").succ) assert_equal(S("2000aaa"), S("1999zzz").succ) assert_equal(S("AAAAA000"), S("ZZZZ999").succ) assert_equal(S("*+"), S("**").succ) @@ -1269,6 +1270,10 @@ class TestString < Test::Unit::TestCase assert_equal(S("*+"), a.succ!) assert_equal(S("*+"), a) + a = S("No.9") + assert_equal(S("No.10"), a.succ!) + assert_equal(S("No.10"), a) + assert_equal("aaaaaaaaaaaa", "zzzzzzzzzzz".succ!) assert_equal("aaaaaaaaaaaaaaaaaaaaaaaa", "zzzzzzzzzzzzzzzzzzzzzzz".succ!) end