chop with utf-8. fix #2967

This commit is contained in:
Yasuhiro Matsumoto
2015-09-29 21:22:25 +09:00
parent 2eb2f5b408
commit d5f145076c
2 changed files with 36 additions and 0 deletions
+11
View File
@@ -1318,7 +1318,18 @@ mrb_str_chop_bang(mrb_state *mrb, mrb_value str)
mrb_str_modify(mrb, s);
if (RSTR_LEN(s) > 0) {
mrb_int len;
#ifdef MRB_UTF8_STRING
const char* t = RSTR_PTR(s), *p = t;
const char* e = p + RSTR_LEN(s);
while (p<e) {
mrb_int clen = utf8len(p, e);
if (p + clen>=e) break;
p += clen;
}
len = p - t;
#else
len = RSTR_LEN(s) - 1;
#endif
if (RSTR_PTR(s)[len] == '\n') {
if (len > 0 &&
RSTR_PTR(s)[len-1] == '\r') {