From a2e8e2022bcab4dd87ee5cf6f1ef1d9df1cf4c98 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 27 Jan 2008 14:27:07 +0000 Subject: * include/ruby/oniguruma.h: precise mbclen API redesigned to avoid inline functions. (onigenc_mbclen_charfound): removed. (onigenc_mbclen_needmore): removed. (onigenc_mbclen_recover): removed. (ONIGENC_MBCLEN_CHARFOUND): removed. (ONIGENC_MBCLEN_CHARFOUND_P): defined. (ONIGENC_MBCLEN_CHARFOUND_LEN): defined. (ONIGENC_MBCLEN_INVALID): removed. (ONIGENC_MBCLEN_INVALID_P): defined. (ONIGENC_MBCLEN_NEEDMORE): removed. (ONIGENC_MBCLEN_NEEDMORE_P): defined. (ONIGENC_MBCLEN_NEEDMORE_LEN): defined. (ONIGENC_MBC_ENC_LEN): use onigenc_mbclen_approximate. * regenc.c (onigenc_mbclen_approximate): defined. * include/ruby/encoding.h (MBCLEN_CHARFOUND): removed. (MBCLEN_INVALID): removed. (MBCLEN_NEEDMORE): removed. (MBCLEN_CHARFOUND_P): defined. (MBCLEN_INVALID_P): defined. (MBCLEN_NEEDMORE_P): defined. (MBCLEN_CHARFOUND_LEN): defined. (MBCLEN_NEEDMORE_LEN): defined. * encoding.c: use new API. * re.c: ditto. * string.c: ditto. * parse.y: ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 452e4affc..3c4e2fc98 100644 --- a/string.c +++ b/string.c @@ -170,11 +170,10 @@ coderange_scan(const char *p, long len, rb_encoding *enc) } while (p < e) { int ret = rb_enc_precise_mbclen(p, e, enc); - int len = MBCLEN_CHARFOUND(ret); - if (!len) { + if (!MBCLEN_CHARFOUND_P(ret)) { return ENC_CODERANGE_BROKEN; } - p += len; + p += MBCLEN_CHARFOUND_LEN(ret); if (p < e) { p = search_nonascii(p, e); if (!p) { @@ -190,12 +189,11 @@ coderange_scan(const char *p, long len, rb_encoding *enc) while (p < e) { int ret = rb_enc_precise_mbclen(p, e, enc); - int len = MBCLEN_CHARFOUND(ret); - if (!len) { + if (!MBCLEN_CHARFOUND_P(ret)) { return ENC_CODERANGE_BROKEN; } - p += len; + p += MBCLEN_CHARFOUND_LEN(ret); } if (e < p) { return ENC_CODERANGE_BROKEN; @@ -2017,7 +2015,8 @@ enc_succ_char(char *p, int len, rb_encoding *enc) return NEIGHBOR_WRAPPED; ++((unsigned char*)p)[i]; l = rb_enc_precise_mbclen(p, p+len, enc); - if (MBCLEN_CHARFOUND(l)) { + if (MBCLEN_CHARFOUND_P(l)) { + l = MBCLEN_CHARFOUND_LEN(l); if (l == len) { return NEIGHBOR_FOUND; } @@ -2025,11 +2024,11 @@ enc_succ_char(char *p, int len, rb_encoding *enc) memset(p+l, 0xff, len-l); } } - if (MBCLEN_INVALID(l) && i < len-1) { + if (MBCLEN_INVALID_P(l) && i < len-1) { int len2, l2; for (len2 = len-1; 0 < len2; len2--) { l2 = rb_enc_precise_mbclen(p, p+len2, enc); - if (!MBCLEN_INVALID(l2)) + if (!MBCLEN_INVALID_P(l2)) break; } memset(p+len2+1, 0xff, len-(len2+1)); @@ -2048,7 +2047,8 @@ enc_pred_char(char *p, int len, rb_encoding *enc) return NEIGHBOR_WRAPPED; --((unsigned char*)p)[i]; l = rb_enc_precise_mbclen(p, p+len, enc); - if (MBCLEN_CHARFOUND(l)) { + if (MBCLEN_CHARFOUND_P(l)) { + l = MBCLEN_CHARFOUND_LEN(l); if (l == len) { return NEIGHBOR_FOUND; } @@ -2056,11 +2056,11 @@ enc_pred_char(char *p, int len, rb_encoding *enc) memset(p+l, 0, len-l); } } - if (MBCLEN_INVALID(l) && i < len-1) { + if (MBCLEN_INVALID_P(l) && i < len-1) { int len2, l2; for (len2 = len-1; 0 < len2; len2--) { l2 = rb_enc_precise_mbclen(p, p+len2, enc); - if (!MBCLEN_INVALID(l2)) + if (!MBCLEN_INVALID_P(l2)) break; } memset(p+len2+1, 0, len-(len2+1)); @@ -3300,11 +3300,12 @@ rb_str_inspect(VALUE str) int cc; n = rb_enc_precise_mbclen(p, pend, enc); - if (!MBCLEN_CHARFOUND(n)) { + if (!MBCLEN_CHARFOUND_P(n)) { p++; n = 1; goto escape_codepoint; } + n = MBCLEN_CHARFOUND_LEN(n); c = rb_enc_codepoint(p, pend, enc); n = rb_enc_codelen(c, enc); @@ -3313,7 +3314,7 @@ rb_str_inspect(VALUE str) if (c == '"'|| c == '\\' || (c == '#' && p < pend && - MBCLEN_CHARFOUND(rb_enc_precise_mbclen(p,pend,enc)) && + MBCLEN_CHARFOUND_P(rb_enc_precise_mbclen(p,pend,enc)) && (cc = rb_enc_codepoint(p,pend,enc), (cc == '$' || cc == '@' || cc == '{')))) { prefix_escape(result, c, enc); -- cgit