2008-01-13 20:16:09 +03:00
|
|
|
/**********************************************************************
|
|
|
|
big5.c - Oniguruma (regular expression library)
|
|
|
|
**********************************************************************/
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
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 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
/* E */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
/* F */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
|
|
|
|
};
|
|
|
|
|
2008-01-28 09:33:57 +03:00
|
|
|
typedef enum { FAILURE = -2, ACCEPT = -1, S0 = 0, S1 } 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, 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,
|
2011-05-15 15:55:52 +04:00
|
|
|
/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F
|
2008-01-28 09:33:57 +03:00
|
|
|
},
|
|
|
|
{ /* 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 */ 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, 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,
|
2011-05-15 15:55:52 +04:00
|
|
|
/* f */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, F
|
2009-08-04 04:51:22 +04:00
|
|
|
},
|
|
|
|
{ /* S2 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, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* 9 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* a */ 1, 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
|
2008-01-28 09:33:57 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
#undef A
|
|
|
|
#undef F
|
|
|
|
|
2008-01-13 20:16:09 +03:00
|
|
|
static int
|
2009-08-04 04:51:22 +04:00
|
|
|
big5_mbc_enc_len0(const UChar* p, const UChar* e, int tridx, const int tbl[])
|
2008-01-13 20:16:09 +03:00
|
|
|
{
|
2008-01-28 09:33:57 +03:00
|
|
|
int firstbyte = *p++;
|
2009-08-04 04:51:22 +04:00
|
|
|
state_t s = trans[tridx][firstbyte];
|
2008-01-28 09:33:57 +03:00
|
|
|
#define RETURN(n) \
|
|
|
|
return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n) : \
|
|
|
|
ONIGENC_CONSTRUCT_MBCLEN_INVALID()
|
|
|
|
if (s < 0) RETURN(1);
|
2009-08-04 04:51:22 +04:00
|
|
|
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(tbl[firstbyte]-1);
|
2008-01-28 09:33:57 +03:00
|
|
|
s = trans[s][*p++];
|
|
|
|
RETURN(2);
|
|
|
|
#undef RETURN
|
2008-01-13 20:16:09 +03:00
|
|
|
}
|
|
|
|
|
2009-08-04 04:51:22 +04:00
|
|
|
static int
|
|
|
|
big5_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
|
|
|
|
{
|
2014-09-15 20:18:41 +04:00
|
|
|
return big5_mbc_enc_len0(p, e, 0, EncLen_BIG5);
|
2009-08-04 04:51:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
big5_hkscs_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
|
|
|
|
{
|
2014-09-15 20:18:41 +04:00
|
|
|
return big5_mbc_enc_len0(p, e, 2, EncLen_BIG5_HKSCS);
|
2009-08-04 04:51:22 +04:00
|
|
|
}
|
|
|
|
|
2009-11-17 11:56:11 +03:00
|
|
|
static int
|
|
|
|
big5_uao_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
|
|
|
|
{
|
2014-09-15 20:18:41 +04:00
|
|
|
return big5_mbc_enc_len0(p, e, 2, EncLen_BIG5_UAO);
|
2009-11-17 11:56:11 +03:00
|
|
|
}
|
|
|
|
|
2008-01-13 20:16:09 +03:00
|
|
|
static OnigCodePoint
|
2008-09-18 16:53:25 +04:00
|
|
|
big5_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
|
2008-01-13 20:16:09 +03:00
|
|
|
{
|
2008-09-18 16:53:25 +04:00
|
|
|
return onigenc_mbn_mbc_to_code(enc, p, end);
|
2008-01-13 20:16:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
big5_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
|
|
|
|
{
|
2008-01-15 16:36:18 +03:00
|
|
|
return onigenc_mb2_code_to_mbc(enc, code, buf);
|
2008-01-13 20:16:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
big5_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end,
|
|
|
|
UChar* lower, OnigEncoding enc)
|
|
|
|
{
|
2008-01-15 16:36:18 +03:00
|
|
|
return onigenc_mbn_mbc_case_fold(enc, flag,
|
2008-01-13 20:16:09 +03:00
|
|
|
pp, end, lower);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static int
|
|
|
|
big5_is_mbc_ambiguous(OnigCaseFoldType flag,
|
|
|
|
const UChar** pp, const UChar* end, OnigEncoding enc)
|
|
|
|
{
|
2008-01-15 16:36:18 +03:00
|
|
|
return onigenc_mbn_is_mbc_ambiguous(enc, flag, pp, end);
|
2008-01-13 20:16:09 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
big5_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
|
|
|
|
{
|
2008-01-15 16:36:18 +03:00
|
|
|
return onigenc_mb2_is_code_ctype(enc, code, ctype);
|
2008-01-13 20:16:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const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2009-11-17 11:56:11 +03:00
|
|
|
#define BIG5_UAO_P(enc) ((enc)->precise_mbc_enc_len == big5_uao_mbc_enc_len)
|
|
|
|
|
2009-08-04 04:51:22 +04:00
|
|
|
#define BIG5_ISMB_FIRST(byte) ( \
|
|
|
|
BIG5_HKSCS_P(enc) ? EncLen_BIG5_HKSCS[byte] > 1 : \
|
|
|
|
EncLen_BIG5[byte] > 1 \
|
|
|
|
)
|
2008-01-13 20:16:09 +03:00
|
|
|
#define BIG5_ISMB_TRAIL(byte) BIG5_CAN_BE_TRAIL_TABLE[(byte)]
|
|
|
|
|
|
|
|
static UChar*
|
2008-09-13 23:23:52 +04:00
|
|
|
big5_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
|
2008-01-13 20:16:09 +03:00
|
|
|
{
|
|
|
|
const UChar *p;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (s <= start) return (UChar* )s;
|
|
|
|
p = s;
|
|
|
|
|
|
|
|
if (BIG5_ISMB_TRAIL(*p)) {
|
|
|
|
while (p > start) {
|
|
|
|
if (! BIG5_ISMB_FIRST(*--p)) {
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
2011-05-15 15:55:52 +04:00
|
|
|
}
|
2008-01-13 20:16:09 +03:00
|
|
|
}
|
2008-09-13 23:23:52 +04:00
|
|
|
len = enclen(enc, p, end);
|
2008-01-13 20:16:09 +03:00
|
|
|
if (p + len > s) return (UChar* )p;
|
|
|
|
p += len;
|
|
|
|
return (UChar* )(p + ((s - p) & ~1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-01-15 17:54:40 +03:00
|
|
|
big5_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
|
2008-01-13 20:16:09 +03:00
|
|
|
{
|
|
|
|
const UChar c = *s;
|
|
|
|
|
|
|
|
return (BIG5_ISMB_TRAIL(c) ? FALSE : TRUE);
|
|
|
|
}
|
|
|
|
|
2009-07-24 20:15:53 +04:00
|
|
|
/*
|
|
|
|
* Name: Big5 (preferred MIME name)
|
|
|
|
* MIBenum: 2026
|
|
|
|
* Source: Chinese for Taiwan Multi-byte set.
|
|
|
|
* PCL Symbol Set Id: 18T
|
|
|
|
* Alias: csBig5
|
|
|
|
*/
|
2008-01-13 20:16:09 +03:00
|
|
|
OnigEncodingDefine(big5, BIG5) = {
|
|
|
|
big5_mbc_enc_len,
|
|
|
|
"Big5", /* name */
|
|
|
|
2, /* max enc length */
|
|
|
|
1, /* min enc length */
|
|
|
|
onigenc_is_mbc_newline_0x0a,
|
|
|
|
big5_mbc_to_code,
|
|
|
|
onigenc_mb2_code_to_mbclen,
|
|
|
|
big5_code_to_mbc,
|
|
|
|
big5_mbc_case_fold,
|
|
|
|
onigenc_ascii_apply_all_case_fold,
|
|
|
|
onigenc_ascii_get_case_fold_codes_by_str,
|
|
|
|
onigenc_minimum_property_name_to_ctype,
|
|
|
|
big5_is_code_ctype,
|
|
|
|
onigenc_not_support_get_ctype_code_range,
|
|
|
|
big5_left_adjust_char_head,
|
2012-02-17 11:42:23 +04:00
|
|
|
big5_is_allowed_reverse_match,
|
|
|
|
0,
|
|
|
|
ONIGENC_FLAG_NONE,
|
2008-01-13 20:16:09 +03:00
|
|
|
};
|
2010-11-22 12:35:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Name: CP950
|
|
|
|
* Source: http://msdn.microsoft.com/en-us/goglobal/cc305155.aspx
|
|
|
|
*/
|
|
|
|
ENC_REPLICATE("CP950", "Big5")
|
2009-07-24 20:15:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Name: Big5-HKSCS
|
|
|
|
* MIBenum: 2101
|
2010-11-24 19:40:38 +03:00
|
|
|
* Source: http://www.iana.org/assignments/charset-reg/Big5-HKSCS
|
|
|
|
* Source: http://www.ogcio.gov.hk/ccli/eng/hkscs/mapping_table_2008.html
|
2009-07-24 20:15:53 +04:00
|
|
|
* Alias: None
|
|
|
|
*/
|
2009-08-04 04:51:22 +04:00
|
|
|
OnigEncodingDefine(big5_hkscs, BIG5_HKSCS) = {
|
|
|
|
big5_hkscs_mbc_enc_len,
|
|
|
|
"Big5-HKSCS", /* name */
|
|
|
|
2, /* max enc length */
|
|
|
|
1, /* min enc length */
|
|
|
|
onigenc_is_mbc_newline_0x0a,
|
|
|
|
big5_mbc_to_code,
|
|
|
|
onigenc_mb2_code_to_mbclen,
|
|
|
|
big5_code_to_mbc,
|
|
|
|
big5_mbc_case_fold,
|
|
|
|
onigenc_ascii_apply_all_case_fold,
|
|
|
|
onigenc_ascii_get_case_fold_codes_by_str,
|
|
|
|
onigenc_minimum_property_name_to_ctype,
|
|
|
|
big5_is_code_ctype,
|
|
|
|
onigenc_not_support_get_ctype_code_range,
|
|
|
|
big5_left_adjust_char_head,
|
2012-02-17 11:42:23 +04:00
|
|
|
big5_is_allowed_reverse_match,
|
|
|
|
0,
|
|
|
|
ONIGENC_FLAG_NONE,
|
2009-08-04 04:51:22 +04:00
|
|
|
};
|
2010-11-24 19:40:38 +03:00
|
|
|
ENC_ALIAS("Big5-HKSCS:2008", "Big5-HKSCS")
|
2010-11-22 12:35:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Name: CP951
|
|
|
|
* Source: http://www.microsoft.com/hk/hkscs/default.aspx
|
|
|
|
* Source: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=0e6f5ac8-7baa-4571-b8e8-78b3b776afd7&DisplayLang=en
|
|
|
|
* Source: http://blogs.msdn.com/b/shawnste/archive/2007/03/12/cp-951-hkscs.aspx
|
|
|
|
*/
|
|
|
|
ENC_REPLICATE("CP951", "Big5-HKSCS")
|
2009-11-17 11:56:11 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Name: Big5-UAO [NOT registered by IANA!]
|
|
|
|
* Source: http://moztw.org/docs/big5/table/big5_2003-b2u.txt
|
|
|
|
*/
|
|
|
|
OnigEncodingDefine(big5_uao, BIG5_UAO) = {
|
|
|
|
big5_uao_mbc_enc_len,
|
|
|
|
"Big5-UAO", /* name */
|
|
|
|
2, /* max enc length */
|
|
|
|
1, /* min enc length */
|
|
|
|
onigenc_is_mbc_newline_0x0a,
|
|
|
|
big5_mbc_to_code,
|
|
|
|
onigenc_mb2_code_to_mbclen,
|
|
|
|
big5_code_to_mbc,
|
|
|
|
big5_mbc_case_fold,
|
|
|
|
onigenc_ascii_apply_all_case_fold,
|
|
|
|
onigenc_ascii_get_case_fold_codes_by_str,
|
|
|
|
onigenc_minimum_property_name_to_ctype,
|
|
|
|
big5_is_code_ctype,
|
|
|
|
onigenc_not_support_get_ctype_code_range,
|
|
|
|
big5_left_adjust_char_head,
|
2012-02-17 11:42:23 +04:00
|
|
|
big5_is_allowed_reverse_match,
|
|
|
|
0,
|
|
|
|
ONIGENC_FLAG_NONE,
|
2009-11-17 11:56:11 +03:00
|
|
|
};
|