mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enc/euc_tw.c (euctw_mbc_enc_len): validation implemented.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4622664c43
commit
12e8b588ac
2 changed files with 101 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Jan 30 00:09:37 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* enc/euc_tw.c (euctw_mbc_enc_len): validation implemented.
|
||||
|
||||
Tue Jan 29 22:58:11 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* test/ruby/test_enumerator.rb: add tests to achieve over 90% test
|
||||
|
|
99
enc/euc_tw.c
99
enc/euc_tw.c
|
@ -48,10 +48,105 @@ static const int EncLen_EUCTW[] = {
|
|||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1
|
||||
};
|
||||
|
||||
typedef enum { FAILURE = -2, ACCEPT = -1, S0 = 0, S1, S2, S3 } state_t;
|
||||
#define A ACCEPT
|
||||
#define F FAILURE
|
||||
static const signed char trans[][0x100] = {
|
||||
{ /* S0 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 1 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 2 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 3 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 4 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 5 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 6 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 7 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, 2, F,
|
||||
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* a */ F, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F
|
||||
},
|
||||
{ /* S1 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* a */ F, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* b */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* c */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* d */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* e */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* f */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, F
|
||||
},
|
||||
{ /* S2 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* a */ F, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
/* b */ 3, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
||||
},
|
||||
{ /* S3 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* a */ F, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F
|
||||
}
|
||||
};
|
||||
#undef A
|
||||
#undef F
|
||||
|
||||
static int
|
||||
euctw_mbc_enc_len(const UChar* p, const UChar* end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
|
||||
euctw_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
|
||||
{
|
||||
return EncLen_EUCTW[*p];
|
||||
int firstbyte = *p++;
|
||||
state_t s = trans[0][firstbyte];
|
||||
#define RETURN(n) \
|
||||
return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n) : \
|
||||
ONIGENC_CONSTRUCT_MBCLEN_INVALID()
|
||||
if (s < 0) RETURN(1);
|
||||
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EUCTW[firstbyte]-1);
|
||||
s = trans[s][*p++];
|
||||
if (s < 0) RETURN(2);
|
||||
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(4-2);
|
||||
s = trans[s][*p++];
|
||||
if (s < 0) RETURN(3);
|
||||
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(4-3);
|
||||
s = trans[s][*p++];
|
||||
RETURN(4);
|
||||
#undef RETURN
|
||||
}
|
||||
|
||||
static OnigCodePoint
|
||||
|
|
Loading…
Reference in a new issue