summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-10-01 19:27:35 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-10-01 19:27:35 +0900
commitcb76ed8ec43b32b9e389b7904ac9d68fcb771d2b (patch)
tree0c9a6f676d55791c9f4671129147e29d5b644b53 /src/string.c
parent744578687d915dea05626d0d04a455d946b59dee (diff)
parent7ad75a4a19f9917bc555b53bffbc6e57b67f1f56 (diff)
downloadmruby-cb76ed8ec43b32b9e389b7904ac9d68fcb771d2b.tar.gz
mruby-cb76ed8ec43b32b9e389b7904ac9d68fcb771d2b.zip
Merge pull request #2971 from mattn/utf8-chop
chop with utf-8. fix #2967
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c11
1 files changed, 11 insertions, 0 deletions
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) {
+ 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') {