summaryrefslogtreecommitdiff
path: root/encoding.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-18 12:53:25 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-18 12:53:25 +0000
commit081c802cb9fe84d349bc4ecf26a36eceae431aed (patch)
tree4e0e385b4fd86fd99da61032af2c40db7edf5f76 /encoding.c
parent22987dc7fe5830d8423f8153bef0310339e178f4 (diff)
downloadruby-081c802cb9fe84d349bc4ecf26a36eceae431aed.tar.gz
* grapheme cluster implementation reverted. [ruby-dev:36375]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c19
1 files changed, 11 insertions, 8 deletions
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));
}