Commit 3103d063 authored by mattn's avatar mattn

Fix String#succ. "-a-".succ should be "-b-"

parent 34f40b0a
......@@ -271,14 +271,27 @@ mrb_str_succ_bang(mrb_state *mrb, mrb_value self)
break;
b++;
}
result = mrb_str_new(mrb, (char*) p, b - p);
if (b > e) {
b = p;
result = mrb_str_new_lit(mrb, "");
} else
result = mrb_str_new(mrb, (char*) p, b - p);
while (e >= b) {
if (ISALNUM(*e))
break;
e--;
}
if (e < b)
e = p + l - 1;
while (e >= b) {
if (!ISALNUM(*e)) {
if (*e == 0xff) {
mrb_str_cat_cstr(mrb, result, "\x01");
(*e) = 0;
} else
} else
(*e)++;
break;
}
......
......@@ -285,6 +285,8 @@ assert('String#succ') do
assert_equal "\x01\x00", "\xff".succ
assert_equal "-b", "-a".succ
assert_equal "-aa", "-z".succ
assert_equal "-b-", "-a-".succ
assert_equal "-aa-", "-z-".succ
assert_equal "あb", "あa".succ
assert_equal "あba", "あaz".succ
......@@ -349,6 +351,10 @@ assert('String#succ') do
assert_equal "-b", a
a = "-z"; a.succ!
assert_equal "-aa", a
a = "-a-"; a.succ!
assert_equal "-b-", a
a = "-z-"; a.succ!
assert_equal "-aa-", a
a = "あa"; a.succ!
assert_equal "あb", a
a = "あaz"; a.succ!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment