summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/string.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c
index 2b01cc3a5..8d79defe0 100644
--- a/src/string.c
+++ b/src/string.c
@@ -273,11 +273,17 @@ utf8_strlen(mrb_value str, mrb_int len)
mrb_int total = 0;
char* p = RSTRING_PTR(str);
char* e = p;
+ if (RSTRING(str)->flags & MRB_STR_NO_UTF) {
+ return RSTRING_LEN(str);
+ }
e += len < 0 ? RSTRING_LEN(str) : len;
while (p<e) {
p += utf8len(p, e);
total++;
}
+ if (RSTRING_LEN(str) == total) {
+ RSTRING(str)->flags |= MRB_STR_NO_UTF;
+ }
return total;
}
@@ -652,6 +658,7 @@ MRB_API void
mrb_str_modify(mrb_state *mrb, struct RString *s)
{
check_frozen(mrb, s);
+ s->flags &= ~MRB_STR_NO_UTF;
if (RSTR_SHARED_P(s)) {
mrb_shared_string *shared = s->as.heap.aux.shared;