Commit 68f33d22 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1663 from h2so5/fix-utf8-codepage

fix utf8 codepage
parents 33dc9615 17176666
......@@ -7,7 +7,7 @@
/* TODO: duplicate definition in src/re.h */
#define REGEXP_CLASS "Regexp"
static size_t utf8len_tab[256] =
static const char utf8len_codepage[256] =
{
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
......@@ -16,7 +16,7 @@ static size_t utf8len_tab[256] =
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,1,1,1,1,1,1,1,1,1,1,1,
};
static size_t
......@@ -27,7 +27,7 @@ utf8len(unsigned char* p)
if (*p == 0)
return 1;
len = utf8len_tab[*p];
len = utf8len_codepage[*p];
for (i = 1; i < len; ++i)
if ((p[i] & 0xc0) != 0x80)
return 1;
......
......@@ -25,3 +25,8 @@ assert('String#reverse!', '15.2.10.5.30') do
assert_equal '!界世わちにんこ', a
assert_equal '!界世わちにんこ', 'こんにちわ世界!'.reverse!
end
assert('Invalid sequence') do
assert_equal 5, "\xF8\x88\x80\x80\x80".size
assert_equal 6, "\xFC\x84\x80\x80\x80\x80".size
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment