mruby-string-utf8: str_subseq takes UTF-8 index, not byte index; ref #2076

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-04-18 23:45:26 +09:00
parent 280f9dfc19
commit b2422cf021
+3 -2
View File
@@ -636,7 +636,8 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
while (ptr < eptr &&
(end = mrb_memsearch(sptr, slen, ptr, eptr - ptr)) >= 0) {
mrb_ary_push(mrb, result, str_subseq(mrb, str, ptr - temp, end));
// mrb_ary_push(mrb, result, str_subseq(mrb, str, ptr - temp, end));
mrb_ary_push(mrb, result, mrb_str_new(mrb, ptr, end));
mrb_gc_arena_restore(mrb, ai);
ptr += end + slen;
if (lim_p && lim <= ++i) break;
@@ -652,7 +653,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
tmp = mrb_str_new_lit(mrb, "");
}
else {
tmp = str_subseq(mrb, str, beg, RSTRING_LEN(str)-beg);
tmp = mrb_str_new(mrb, RSTRING_PTR(str)+beg, RSTRING_LEN(str)-beg);
}
mrb_ary_push(mrb, result, tmp);
}