aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-27 14:27:07 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-27 14:27:07 +0000
commitfc208c1bd56a4e3fc03cb2f54616b4479f4b0e41 (patch)
treef29aa519ea99cfcb7a7f13ec44508510d9291a0b /string.c
parent526ab1f0d15247da489cb2fc8af8d4c3f1a71cc2 (diff)
downloadruby-fc208c1bd56a4e3fc03cb2f54616b4479f4b0e41.tar.gz
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@15280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/string.c b/string.c
index 452e4affc1..3c4e2fc981 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);