Commit 4ece1e3e authored by mattn's avatar mattn

"-a-a-".succ should be "-a-b-"

parent 3103d063
......@@ -266,25 +266,27 @@ mrb_str_succ_bang(mrb_state *mrb, mrb_value self)
t = e = p + l;
*(e--) = 0;
while (b < e) {
if (ISALNUM(*b))
break;
b++;
}
if (b > e) {
b = p;
result = mrb_str_new_lit(mrb, "");
} else
result = mrb_str_new(mrb, (char*) p, b - p);
// find trailing ascii/number
while (e >= b) {
if (ISALNUM(*e))
break;
e--;
}
if (e < b)
if (e < b) {
e = p + l - 1;
result = mrb_str_new_lit(mrb, "");
} else {
// find leading letter of the ascii/number
b = e;
while (b > p) {
if (!ISALNUM(*b) || (ISALNUM(*b) && *b != '9' && *b != 'z' && *b != 'Z'))
break;
b--;
}
if (!ISALNUM(*b))
b++;
result = mrb_str_new(mrb, (char*) p, b - p);
}
while (e >= b) {
if (!ISALNUM(*e)) {
......
......@@ -285,6 +285,7 @@ assert('String#succ') do
assert_equal "\x01\x00", "\xff".succ
assert_equal "-b", "-a".succ
assert_equal "-aa", "-z".succ
assert_equal "-a-b-", "-a-a-".succ
assert_equal "-b-", "-a-".succ
assert_equal "-aa-", "-z-".succ
assert_equal "あb", "あa".succ
......@@ -351,6 +352,8 @@ assert('String#succ') do
assert_equal "-b", a
a = "-z"; a.succ!
assert_equal "-aa", a
a = "-a-a-"; a.succ!
assert_equal "-a-b-", a
a = "-a-"; a.succ!
assert_equal "-b-", a
a = "-z-"; 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