aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/string.c b/string.c
index 6569215d17..300aacb91f 100644
--- a/string.c
+++ b/string.c
@@ -4967,6 +4967,7 @@ trnext(struct tr *t, rb_encoding *enc)
for (;;) {
if (!t->gen) {
+nextpart:
if (t->p == t->pend) return -1;
if (rb_enc_ascget(t->p, t->pend, &n, enc) == '\\' && t->p + n < t->pend) {
t->p += n;
@@ -4995,12 +4996,20 @@ trnext(struct tr *t, rb_encoding *enc)
}
return t->now;
}
- else if (++t->now < t->max) {
- return t->now;
- }
else {
- t->gen = 0;
- return t->max;
+ while (ONIGENC_CODE_TO_MBCLEN(enc, ++t->now) <= 0) {
+ if (t->now == t->max) {
+ t->gen = 0;
+ goto nextpart;
+ }
+ }
+ if (t->now < t->max) {
+ return t->now;
+ }
+ else {
+ t->gen = 0;
+ return t->max;
+ }
}
}
}