From 081c802cb9fe84d349bc4ecf26a36eceae431aed Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 18 Sep 2008 12:53:25 +0000 Subject: * grapheme cluster implementation reverted. [ruby-dev:36375] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- encoding.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'encoding.c') diff --git a/encoding.c b/encoding.c index 29d97de1c8..78887de730 100644 --- a/encoding.c +++ b/encoding.c @@ -735,16 +735,20 @@ rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc) int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc) { - unsigned int c; - int l, l2; + unsigned int c, l; if (e <= p) return -1; + if (rb_enc_asciicompat(enc)) { + c = (unsigned char)*p; + if (!ISASCII(c)) + return -1; + if (len) *len = 1; + return c; + } l = rb_enc_precise_mbclen(p, e, enc); if (!MBCLEN_CHARFOUND_P(l)) return -1; - c = rb_enc_mbc_precise_codepoint(p, e, &l2, enc); - if (l != l2) - return -1; + c = rb_enc_mbc_to_codepoint(p, e, enc); if (!rb_enc_isascii(c, enc)) return -1; if (len) *len = l; @@ -755,12 +759,11 @@ unsigned int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc) { int r; - OnigCodePoint c; if (e <= p) rb_raise(rb_eArgError, "empty string"); - c = rb_enc_mbc_precise_codepoint(p, e, &r, enc); + r = rb_enc_precise_mbclen(p, e, enc); if (MBCLEN_CHARFOUND_P(r)) - return c; + return rb_enc_mbc_to_codepoint(p, e, enc); else rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc)); } -- cgit v1.2.3