From 05bc47773ab5be6ce461c8180e2d4b7cb727f76f Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 4 Jul 2013 06:52:33 +0000 Subject: * string.c (rb_str_succ): use ONIGENC_MBCLEN_CHARFOUND_P correctly. * string.c (rb_str_dump): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 2003a075bb..46658e0a12 100644 --- a/string.c +++ b/string.c @@ -2976,7 +2976,9 @@ rb_str_succ(VALUE orig) break; } } - if ((l = rb_enc_precise_mbclen(s, e, enc)) <= 0) continue; + l = rb_enc_precise_mbclen(s, e, enc); + if (!ONIGENC_MBCLEN_CHARFOUND_P(l)) continue; + l = ONIGENC_MBCLEN_CHARFOUND_LEN(l); neighbor = enc_succ_alnum_char(s, l, enc, carry); switch (neighbor) { case NEIGHBOR_NOT_CHAR: @@ -2995,7 +2997,9 @@ rb_str_succ(VALUE orig) s = e; while ((s = rb_enc_prev_char(sbeg, s, e, enc)) != 0) { enum neighbor_char neighbor; - if ((l = rb_enc_precise_mbclen(s, e, enc)) <= 0) continue; + l = rb_enc_precise_mbclen(s, e, enc); + if (!ONIGENC_MBCLEN_CHARFOUND_P(l)) continue; + l = ONIGENC_MBCLEN_CHARFOUND_LEN(l); neighbor = enc_succ_char(s, l, enc); if (neighbor == NEIGHBOR_FOUND) return str; @@ -4618,9 +4622,9 @@ rb_str_dump(VALUE str) len++; } else { - if (u8) { /* \u{NN} */ + if (u8 && c > 0x7F) { /* \u{NN} */ int n = rb_enc_precise_mbclen(p-1, pend, enc); - if (MBCLEN_CHARFOUND_P(n-1)) { + if (MBCLEN_CHARFOUND_P(n)) { unsigned int cc = rb_enc_mbc_to_codepoint(p-1, pend, enc); while (cc >>= 4) len++; len += 5; -- cgit v1.2.3