string.c: need to adjust index for UTF-8.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-09-01 06:59:31 +09:00
parent 7ffffbfe01
commit 41d0b343e6
+2 -2
View File
@@ -2868,13 +2868,13 @@ sub_replace(mrb_state *mrb, mrb_value self)
mrb_str_cat(mrb, result, "\\", 1);
break;
case '`':
mrb_str_cat(mrb, result, RSTRING_PTR(self), found);
mrb_str_cat(mrb, result, RSTRING_PTR(self), chars2bytes(self, 0, found));
break;
case '&': case '0':
mrb_str_cat(mrb, result, match, mlen);
break;
case '\'':
offset = found + mlen;
offset = chars2bytes(self, 0, found) + mlen;
if (RSTRING_LEN(self) > offset) {
mrb_str_cat(mrb, result, RSTRING_PTR(self)+offset, RSTRING_LEN(self)-offset);
}