From d5f145076ce11ed4e47e11af065ee9e36bf5f369 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 29 Sep 2015 21:22:25 +0900 Subject: chop with utf-8. fix #2967 --- src/string.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/string.c b/src/string.c index 6cad6a4ac..b597c3da9 100644 --- a/src/string.c +++ b/src/string.c @@ -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) 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') { -- cgit v1.2.3