Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Merge Onigmo-5.13.1. [ruby-dev:45057] [Feature #5820]

  https://github.com/k-takata/Onigmo
  cp reg{comp,enc,error,exec,parse,syntax}.c reg{enc,int,parse}.h
  cp oniguruma.h
  cp tool/enc-unicode.rb
  cp -r enc/

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 0424e152c684a85f4b0691f1e84aec203115333d 1 parent 5362e7f
@nurse nurse authored
Showing with 28,950 additions and 20,307 deletions.
  1. +14 −0 ChangeLog
  2. +3 −0  NEWS
  3. +5 −2 enc/ascii.c
  4. +9 −3 enc/big5.c
  5. +3 −1 enc/cp949.c
  6. +2 −1  enc/emacs_mule.c
  7. +262 −23 enc/euc_jp.c
  8. +3 −1 enc/euc_kr.c
  9. +3 −1 enc/euc_tw.c
  10. +3 −1 enc/gb18030.c
  11. +3 −1 enc/gbk.c
  12. +3 −1 enc/iso_8859_1.c
  13. +3 −1 enc/iso_8859_10.c
  14. +3 −1 enc/iso_8859_11.c
  15. +3 −1 enc/iso_8859_13.c
  16. +3 −1 enc/iso_8859_14.c
  17. +3 −1 enc/iso_8859_15.c
  18. +3 −1 enc/iso_8859_16.c
  19. +3 −1 enc/iso_8859_2.c
  20. +3 −1 enc/iso_8859_3.c
  21. +3 −1 enc/iso_8859_4.c
  22. +3 −1 enc/iso_8859_5.c
  23. +3 −1 enc/iso_8859_6.c
  24. +3 −1 enc/iso_8859_7.c
  25. +3 −1 enc/iso_8859_8.c
  26. +3 −1 enc/iso_8859_9.c
  27. +3 −1 enc/koi8_r.c
  28. +3 −1 enc/koi8_u.c
  29. +1,162 −0 enc/mktable.c
  30. +233 −47 enc/shift_jis.c
  31. +6 −1,935 enc/unicode.c
  32. +2,230 −0 enc/unicode/casefold.h
  33. +22,545 −17,685 enc/unicode/name2ctype.h
  34. +3 −1 enc/us_ascii.c
  35. +5 −6 enc/utf_16be.c
  36. +5 −6 enc/utf_16le.c
  37. +5 −7 enc/utf_32be.c
  38. +5 −7 enc/utf_32le.c
  39. +6 −6 enc/utf_8.c
  40. +3 −1 enc/windows_1251.c
  41. +80 −0 enc/windows_31j.c
  42. +61 −29 include/ruby/oniguruma.h
  43. +451 −93 regcomp.c
  44. +27 −5 regenc.c
  45. +11 −3 regenc.h
  46. +14 −9 regerror.c
  47. +671 −156 regexec.c
  48. +82 −19 regint.h
  49. +840 −213 regparse.c
  50. +7 −2 regparse.h
  51. +78 −6 regsyntax.c
  52. +1 −1  test/ruby/enc/test_euc_jp.rb
  53. +1 −1  test/ruby/enc/test_shift_jis.rb
  54. +57 −18 tool/enc-unicode.rb
View
14 ChangeLog
@@ -1,3 +1,17 @@
+Fri Feb 17 15:38:53 2012 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * Merge Onigmo-5.13.1. [ruby-dev:45057] [Feature #5820]
+ https://github.com/k-takata/Onigmo
+ cp reg{comp,enc,error,exec,parse,syntax}.c reg{enc,int,parse}.h
+ cp oniguruma.h
+ cp tool/enc-unicode.rb
+ cp -r enc/
+
+Fri Feb 17 12:35:55 2012 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * tool/merger.rb: remove borders from the commit message which is used
+ when the commit doesn't change ChangeLog.
+
Fri Feb 17 15:20:30 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* enum.c (enum_each_slice): arrays to be yielded can be newly
View
3  NEWS
@@ -72,6 +72,9 @@ with all sufficient information, see the ChangeLog file.
See above.
+ * Merge Onigmo.
+ https://github.com/k-takata/Onigmo
+
* incompatible changes:
The :close_others option is true by default for system() and exec().
Also, the close-on-exec flag is set by default for all new file descriptors.
View
7 enc/ascii.c
@@ -1,8 +1,9 @@
/**********************************************************************
- ascii.c - Oniguruma (regular expression library)
+ ascii.c - Onigmo (Oniguruma-mod) (regular expression library)
**********************************************************************/
/*-
* Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
+ * Copyright (c) 2011 K.Takata <kentkt AT csc DOT jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -45,7 +46,9 @@ OnigEncodingDefine(ascii, ASCII) = {
onigenc_ascii_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("BINARY", "ASCII-8BIT")
ENC_REPLICATE("IBM437", "ASCII-8BIT")
View
12 enc/big5.c
@@ -299,7 +299,9 @@ OnigEncodingDefine(big5, BIG5) = {
big5_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
big5_left_adjust_char_head,
- big5_is_allowed_reverse_match
+ big5_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
/*
@@ -331,7 +333,9 @@ OnigEncodingDefine(big5_hkscs, BIG5_HKSCS) = {
big5_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
big5_left_adjust_char_head,
- big5_is_allowed_reverse_match
+ big5_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("Big5-HKSCS:2008", "Big5-HKSCS")
@@ -363,5 +367,7 @@ OnigEncodingDefine(big5_uao, BIG5_UAO) = {
big5_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
big5_left_adjust_char_head,
- big5_is_allowed_reverse_match
+ big5_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
View
4 enc/cp949.c
@@ -210,7 +210,9 @@ OnigEncodingDefine(cp949, CP949) = {
cp949_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
cp949_left_adjust_char_head,
- cp949_is_allowed_reverse_match
+ cp949_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
/*
* Name: CP949
View
3  enc/emacs_mule.c
@@ -334,7 +334,8 @@ OnigEncodingDefine(emacs_mule, Emacs_Mule) = {
onigenc_not_support_get_ctype_code_range,
left_adjust_char_head,
onigenc_always_true_is_allowed_reverse_match,
- 0
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_REPLICATE("stateless-ISO-2022-JP", "Emacs-Mule")
View
285 enc/euc_jp.c
@@ -1,8 +1,9 @@
/**********************************************************************
- euc_jp.c - Oniguruma (regular expression library)
+ euc_jp.c - Onigmo (Oniguruma-mod) (regular expression library)
**********************************************************************/
/*-
- * Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
+ * Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
+ * Copyright (c) 2011 K.Takata <kentkt AT csc DOT jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,7 +30,6 @@
#include "regint.h"
-
#define eucjp_islead(c) ((UChar )((c) - 0xa1) > 0xfe - 0xa1)
static const int EncLen_EUCJP[] = {
@@ -114,6 +114,97 @@ static const signed char trans[][0x100] = {
#undef A
#undef F
+static const OnigPairCaseFoldCodes CaseFoldMap[] = {
+ /* Fullwidth Alphabet */
+ { 0xa3c1, 0xa3e1 },
+ { 0xa3c2, 0xa3e2 },
+ { 0xa3c3, 0xa3e3 },
+ { 0xa3c4, 0xa3e4 },
+ { 0xa3c5, 0xa3e5 },
+ { 0xa3c6, 0xa3e6 },
+ { 0xa3c7, 0xa3e7 },
+ { 0xa3c8, 0xa3e8 },
+ { 0xa3c9, 0xa3e9 },
+ { 0xa3ca, 0xa3ea },
+ { 0xa3cb, 0xa3eb },
+ { 0xa3cc, 0xa3ec },
+ { 0xa3cd, 0xa3ed },
+ { 0xa3ce, 0xa3ee },
+ { 0xa3cf, 0xa3ef },
+ { 0xa3d0, 0xa3f0 },
+ { 0xa3d1, 0xa3f1 },
+ { 0xa3d2, 0xa3f2 },
+ { 0xa3d3, 0xa3f3 },
+ { 0xa3d4, 0xa3f4 },
+ { 0xa3d5, 0xa3f5 },
+ { 0xa3d6, 0xa3f6 },
+ { 0xa3d7, 0xa3f7 },
+ { 0xa3d8, 0xa3f8 },
+ { 0xa3d9, 0xa3f9 },
+ { 0xa3da, 0xa3fa },
+
+ /* Greek */
+ { 0xa6a1, 0xa6c1 },
+ { 0xa6a2, 0xa6c2 },
+ { 0xa6a3, 0xa6c3 },
+ { 0xa6a4, 0xa6c4 },
+ { 0xa6a5, 0xa6c5 },
+ { 0xa6a6, 0xa6c6 },
+ { 0xa6a7, 0xa6c7 },
+ { 0xa6a8, 0xa6c8 },
+ { 0xa6a9, 0xa6c9 },
+ { 0xa6aa, 0xa6ca },
+ { 0xa6ab, 0xa6cb },
+ { 0xa6ac, 0xa6cc },
+ { 0xa6ad, 0xa6cd },
+ { 0xa6ae, 0xa6ce },
+ { 0xa6af, 0xa6cf },
+ { 0xa6b0, 0xa6d0 },
+ { 0xa6b1, 0xa6d1 },
+ { 0xa6b2, 0xa6d2 },
+ { 0xa6b3, 0xa6d3 },
+ { 0xa6b4, 0xa6d4 },
+ { 0xa6b5, 0xa6d5 },
+ { 0xa6b6, 0xa6d6 },
+ { 0xa6b7, 0xa6d7 },
+ { 0xa6b8, 0xa6d8 },
+
+ /* Cyrillic */
+ { 0xa7a1, 0xa7d1 },
+ { 0xa7a2, 0xa7d2 },
+ { 0xa7a3, 0xa7d3 },
+ { 0xa7a4, 0xa7d4 },
+ { 0xa7a5, 0xa7d5 },
+ { 0xa7a6, 0xa7d6 },
+ { 0xa7a7, 0xa7d7 },
+ { 0xa7a8, 0xa7d8 },
+ { 0xa7a9, 0xa7d9 },
+ { 0xa7aa, 0xa7da },
+ { 0xa7ab, 0xa7db },
+ { 0xa7ac, 0xa7dc },
+ { 0xa7ad, 0xa7dd },
+ { 0xa7ae, 0xa7de },
+ { 0xa7af, 0xa7df },
+ { 0xa7b0, 0xa7e0 },
+ { 0xa7b1, 0xa7e1 },
+ { 0xa7b2, 0xa7e2 },
+ { 0xa7b3, 0xa7e3 },
+ { 0xa7b4, 0xa7e4 },
+ { 0xa7b5, 0xa7e5 },
+ { 0xa7b6, 0xa7e6 },
+ { 0xa7b7, 0xa7e7 },
+ { 0xa7b8, 0xa7e8 },
+ { 0xa7b9, 0xa7e9 },
+ { 0xa7ba, 0xa7ea },
+ { 0xa7bb, 0xa7eb },
+ { 0xa7bc, 0xa7ec },
+ { 0xa7bd, 0xa7ed },
+ { 0xa7be, 0xa7ee },
+ { 0xa7bf, 0xa7ef },
+ { 0xa7c0, 0xa7f0 },
+ { 0xa7c1, 0xa7f1 },
+};
+
static int
mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
{
@@ -138,7 +229,7 @@ mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
int c, i, len;
OnigCodePoint n;
- len = enclen(enc, p, end);
+ len = mbc_enc_len(p, end, enc);
n = (OnigCodePoint )*p++;
if (len == 1) return n;
@@ -154,10 +245,10 @@ static int
code_to_mbclen(OnigCodePoint code, OnigEncoding enc ARG_UNUSED)
{
if (ONIGENC_IS_CODE_ASCII(code)) return 1;
- else if (code > 0xffffff)
- return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
- else if (code & 0x800000) return 3;
- else if (code & 0x8000) return 2;
+ else if (code > 0x00ffffff)
+ return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
+ else if ((code & 0xff808080) == 0x00808080) return 3;
+ else if ((code & 0xffff8080) == 0x00008080) return 2;
else
return ONIGERR_INVALID_CODE_POINT_VALUE;
}
@@ -191,10 +282,87 @@ code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
*p++ = (UChar )(code & 0xff);
#if 1
- if (enclen(enc, buf, p) != (p - buf))
+ if (mbc_enc_len(buf, p, enc) != (p - buf))
return ONIGERR_INVALID_CODE_POINT_VALUE;
#endif
- return (int)(p - buf);
+ return (int )(p - buf);
+}
+
+static int
+apply_all_case_fold(OnigCaseFoldType flag,
+ OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc)
+{
+ return onigenc_apply_all_case_fold_with_map(
+ sizeof(CaseFoldMap)/sizeof(OnigPairCaseFoldCodes), CaseFoldMap, 0,
+ flag, f, arg);
+}
+
+static OnigCodePoint
+get_lower_case(OnigCodePoint code)
+{
+ if (ONIGENC_IS_IN_RANGE(code, 0xa3c1, 0xa3da)) {
+ /* Fullwidth Alphabet */
+ return (OnigCodePoint )(code + 0x0020);
+ }
+ else if (ONIGENC_IS_IN_RANGE(code, 0xa6a1, 0xa6b8)) {
+ /* Greek */
+ return (OnigCodePoint )(code + 0x0020);
+ }
+ else if (ONIGENC_IS_IN_RANGE(code, 0xa7a1, 0xa7c1)) {
+ /* Cyrillic */
+ return (OnigCodePoint )(code + 0x0030);
+ }
+ return code;
+}
+
+static OnigCodePoint
+get_upper_case(OnigCodePoint code)
+{
+ if (ONIGENC_IS_IN_RANGE(code, 0xa3e1, 0xa3fa)) {
+ /* Fullwidth Alphabet */
+ return (OnigCodePoint )(code - 0x0020);
+ }
+ else if (ONIGENC_IS_IN_RANGE(code, 0xa6c1, 0xa6d8)) {
+ /* Greek */
+ return (OnigCodePoint )(code - 0x0020);
+ }
+ else if (ONIGENC_IS_IN_RANGE(code, 0xa7d1, 0xa7f1)) {
+ /* Cyrillic */
+ return (OnigCodePoint )(code - 0x0030);
+ }
+ return code;
+}
+
+static int
+get_case_fold_codes_by_str(OnigCaseFoldType flag,
+ const OnigUChar* p, const OnigUChar* end,
+ OnigCaseFoldCodeItem items[], OnigEncoding enc)
+{
+ int len;
+ OnigCodePoint code, code_lo, code_up;
+
+ code = mbc_to_code(p, end, enc);
+ if (ONIGENC_IS_ASCII_CODE(code))
+ return onigenc_ascii_get_case_fold_codes_by_str(flag, p, end, items, enc);
+
+ len = mbc_enc_len(p, end, enc);
+ code_lo = get_lower_case(code);
+ code_up = get_upper_case(code);
+
+ if (code != code_lo) {
+ items[0].byte_len = len;
+ items[0].code_len = 1;
+ items[0].code[0] = code_lo;
+ return 1;
+ }
+ else if (code != code_up) {
+ items[0].byte_len = len;
+ items[0].code_len = 1;
+ items[0].code[0] = code_up;
+ return 1;
+ }
+
+ return 0;
}
static int
@@ -202,7 +370,6 @@ mbc_case_fold(OnigCaseFoldType flag,
const UChar** pp, const UChar* end, UChar* lower,
OnigEncoding enc)
{
- int len;
const UChar* p = *pp;
if (ONIGENC_IS_MBC_ASCII(p)) {
@@ -211,12 +378,11 @@ mbc_case_fold(OnigCaseFoldType flag,
return 1;
}
else {
- int i;
+ OnigCodePoint code;
+ int len;
- len = enclen(enc, p, end);
- for (i = 0; i < len; i++) {
- *lower++ = *p++;
- }
+ code = get_lower_case(mbc_to_code(p, end, enc));
+ len = code_to_mbc(code, lower, enc);
(*pp) += len;
return len; /* return byte length of converted char to lower */
}
@@ -235,7 +401,7 @@ left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, Onig
p = s;
while (!eucjp_islead(*p) && p > start) p--;
- len = enclen(enc, p, end);
+ len = mbc_enc_len(p, end, enc);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
@@ -260,15 +426,83 @@ static hash_table_type* PropertyNameTable;
static const OnigCodePoint CR_Hiragana[] = {
1,
+#ifdef ENC_EUC_JIS_2004
+ 0xa4a1, 0xa4fb
+#else
0xa4a1, 0xa4f3
+#endif
}; /* CR_Hiragana */
+#ifdef ENC_EUC_JIS_2004
+static const OnigCodePoint CR_Katakana[] = {
+ 5,
+ 0x8ea6, 0x8eaf, /* JIS X 0201 Katakana */
+ 0x8eb1, 0x8edd, /* JIS X 0201 Katakana */
+ 0xa5a1, 0xa5fe,
+ 0xa6ee, 0xa6fe,
+ 0xa7f2, 0xa7f5,
+}; /* CR_Katakana */
+#else
static const OnigCodePoint CR_Katakana[] = {
3,
+ 0x8ea6, 0x8eaf, /* JIS X 0201 Katakana */
+ 0x8eb1, 0x8edd, /* JIS X 0201 Katakana */
0xa5a1, 0xa5f6,
- 0xaaa6, 0xaaaf,
- 0xaab1, 0xaadd
}; /* CR_Katakana */
+#endif
+
+#ifdef ENC_EUC_JIS_2004
+static const OnigCodePoint CR_Han[] = {
+ /* EUC-JIS-2004 (JIS X 0213:2004) */
+ 7,
+ /* plane 1 */
+ 0xa1b8, 0xa1b8,
+ 0xaea1, 0xfefe, /* Kanji level 1, 2 and 3 */
+ /* plane 2 */
+ 0x8fa1a1, 0x8fa1fe, /* row 1 */
+ 0x8fa3a1, 0x8fa5fe, /* row 3 .. 5 */
+ 0x8fa8a1, 0x8fa8fe, /* row 8 */
+ 0x8faca1, 0x8faffe, /* row 12 .. 15 */
+ 0x8feea1, 0x8ffef6, /* row 78 .. 94 */
+}; /* CR_Han */
+#else
+static const OnigCodePoint CR_Han[] = {
+ /* EUC-JP (JIS X 0208 based) */
+ 4,
+ 0xa1b8, 0xa1b8,
+ 0xb0a1, 0xcfd3, /* Kanji level 1 */
+ 0xd0a1, 0xf4a6, /* Kanji level 2 */
+ 0x8fb0a1, 0x8fedf3 /* JIS X 0212 Supplemental Kanji (row 16 .. 77) */
+}; /* CR_Han */
+#endif
+
+static const OnigCodePoint CR_Latin[] = {
+ 4,
+ 0x0041, 0x005a,
+ 0x0061, 0x007a,
+ 0xa3c1, 0xa3da,
+ 0xa3e1, 0xa3fa,
+ /* TODO: add raw 8 .. 11 to support EUC-JIS-2004 */
+ /* TODO: add JIS X 0212 row 9 .. 11 */
+}; /* CR_Latin */
+
+static const OnigCodePoint CR_Greek[] = {
+ 2,
+ 0xa6a1, 0xa6b8,
+#ifdef ENC_EUC_JIS_2004
+ 0xa6c1, 0xa6d9,
+#else
+ 0xa6c1, 0xa6d8,
+ /* TODO: add JIS X 0212 row 6 */
+#endif
+}; /* CR_Greek */
+
+static const OnigCodePoint CR_Cyrillic[] = {
+ 2,
+ 0xa7a1, 0xa7c1,
+ 0xa7d1, 0xa7f1,
+ /* TODO: add JIS X 0212 row 7 */
+}; /* CR_Cyrillic */
static int
init_property_list(void)
@@ -277,6 +511,10 @@ init_property_list(void)
PROPERTY_LIST_ADD_PROP("hiragana", CR_Hiragana);
PROPERTY_LIST_ADD_PROP("katakana", CR_Katakana);
+ PROPERTY_LIST_ADD_PROP("han", CR_Han);
+ PROPERTY_LIST_ADD_PROP("latin", CR_Latin);
+ PROPERTY_LIST_ADD_PROP("greek", CR_Greek);
+ PROPERTY_LIST_ADD_PROP("cyrillic", CR_Cyrillic);
PropertyInited = 1;
end:
@@ -300,7 +538,7 @@ property_name_to_ctype(OnigEncoding enc, UChar* p, UChar* end)
return onigenc_minimum_property_name_to_ctype(enc, s, e);
}
- return (int)ctype;
+ return (int )ctype;
}
static int
@@ -360,14 +598,15 @@ OnigEncodingDefine(euc_jp, EUC_JP) = {
code_to_mbclen,
code_to_mbc,
mbc_case_fold,
- onigenc_ascii_apply_all_case_fold,
- onigenc_ascii_get_case_fold_codes_by_str,
+ apply_all_case_fold,
+ get_case_fold_codes_by_str,
property_name_to_ctype,
is_code_ctype,
get_ctype_code_range,
left_adjust_char_head,
is_allowed_reverse_match,
- 0
+ 0,
+ ONIGENC_FLAG_NONE,
};
/*
* Name: EUC-JP
View
4 enc/euc_kr.c
@@ -187,6 +187,8 @@ OnigEncodingDefine(euc_kr, EUC_KR) = {
euckr_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
euckr_left_adjust_char_head,
- euckr_is_allowed_reverse_match
+ euckr_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("eucKR", "EUC-KR")
View
4 enc/euc_tw.c
@@ -220,6 +220,8 @@ OnigEncodingDefine(euc_tw, EUC_TW) = {
euctw_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
euctw_left_adjust_char_head,
- euctw_is_allowed_reverse_match
+ euctw_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("eucTW", "EUC-TW")
View
4 enc/gb18030.c
@@ -596,6 +596,8 @@ OnigEncodingDefine(gb18030, GB18030) = {
gb18030_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
gb18030_left_adjust_char_head,
- gb18030_is_allowed_reverse_match
+ gb18030_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
View
4 enc/gbk.c
@@ -210,7 +210,9 @@ OnigEncodingDefine(gbk, GBK) = {
gbk_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
gbk_left_adjust_char_head,
- gbk_is_allowed_reverse_match
+ gbk_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
/*
* Name: GBK
View
4 enc/iso_8859_1.c
@@ -272,7 +272,9 @@ OnigEncodingDefine(iso_8859_1, ISO_8859_1) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-1", "ISO-8859-1")
View
4 enc/iso_8859_10.c
@@ -239,6 +239,8 @@ OnigEncodingDefine(iso_8859_10, ISO_8859_10) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-10", "ISO-8859-10")
View
4 enc/iso_8859_11.c
@@ -92,7 +92,9 @@ OnigEncodingDefine(iso_8859_11, ISO_8859_11) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-11", "ISO-8859-11")
View
4 enc/iso_8859_13.c
@@ -228,7 +228,9 @@ OnigEncodingDefine(iso_8859_13, ISO_8859_13) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-13", "ISO-8859-13")
View
4 enc/iso_8859_14.c
@@ -241,6 +241,8 @@ OnigEncodingDefine(iso_8859_14, ISO_8859_14) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-14", "ISO-8859-14")
View
4 enc/iso_8859_15.c
@@ -235,6 +235,8 @@ OnigEncodingDefine(iso_8859_15, ISO_8859_15) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-15", "ISO-8859-15")
View
4 enc/iso_8859_16.c
@@ -237,6 +237,8 @@ OnigEncodingDefine(iso_8859_16, ISO_8859_16) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-16", "ISO-8859-16")
View
4 enc/iso_8859_2.c
@@ -237,7 +237,9 @@ OnigEncodingDefine(iso_8859_2, ISO_8859_2) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-2", "ISO-8859-2")
View
4 enc/iso_8859_3.c
@@ -235,6 +235,8 @@ OnigEncodingDefine(iso_8859_3, ISO_8859_3) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-3", "ISO-8859-3")
View
4 enc/iso_8859_4.c
@@ -237,6 +237,8 @@ OnigEncodingDefine(iso_8859_4, ISO_8859_4) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-4", "ISO-8859-4")
View
4 enc/iso_8859_5.c
@@ -225,6 +225,8 @@ OnigEncodingDefine(iso_8859_5, ISO_8859_5) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-5", "ISO-8859-5")
View
4 enc/iso_8859_6.c
@@ -92,7 +92,9 @@ OnigEncodingDefine(iso_8859_6, ISO_8859_6) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-6", "ISO-8859-6")
View
4 enc/iso_8859_7.c
@@ -222,7 +222,9 @@ OnigEncodingDefine(iso_8859_7, ISO_8859_7) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-7", "ISO-8859-7")
View
4 enc/iso_8859_8.c
@@ -92,7 +92,9 @@ OnigEncodingDefine(iso_8859_8, ISO_8859_8) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-8", "ISO-8859-8")
View
4 enc/iso_8859_9.c
@@ -228,7 +228,9 @@ OnigEncodingDefine(iso_8859_9, ISO_8859_9) = {
is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("ISO8859-9", "ISO-8859-9")
View
4 enc/koi8_r.c
@@ -213,7 +213,9 @@ OnigEncodingDefine(koi8_r, KOI8_R) = {
koi8_r_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
ENC_ALIAS("CP878", "KOI8-R")
View
4 enc/koi8_u.c
@@ -217,5 +217,7 @@ OnigEncodingDefine(koi8_u, KOI8_U) = {
koi8_u_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
+ onigenc_always_true_is_allowed_reverse_match,
+ 0,
+ ONIGENC_FLAG_NONE,
};
View
1,162 enc/mktable.c
@@ -0,0 +1,1162 @@
+/**********************************************************************
+ mktable.c
+**********************************************************************/
+/*-
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <locale.h>
+
+#define __USE_ISOC99
+#include <ctype.h>
+
+#include "regenc.h"
+
+#define ASCII 0
+#define UNICODE_ISO_8859_1 1
+#define ISO_8859_1 2
+#define ISO_8859_2 3
+#define ISO_8859_3 4
+#define ISO_8859_4 5
+#define ISO_8859_5 6
+#define ISO_8859_6 7
+#define ISO_8859_7 8
+#define ISO_8859_8 9
+#define ISO_8859_9 10
+#define ISO_8859_10 11
+#define ISO_8859_11 12
+#define ISO_8859_13 13
+#define ISO_8859_14 14
+#define ISO_8859_15 15
+#define ISO_8859_16 16
+#define KOI8 17
+#define KOI8_R 18
+
+typedef struct {
+ int num;
+ char* name;
+} ENC_INFO;
+
+static ENC_INFO Info[] = {
+ { ASCII, "ASCII" },
+ { UNICODE_ISO_8859_1, "UNICODE_ISO_8859_1" },
+ { ISO_8859_1, "ISO_8859_1" },
+ { ISO_8859_2, "ISO_8859_2" },
+ { ISO_8859_3, "ISO_8859_3" },
+ { ISO_8859_4, "ISO_8859_4" },
+ { ISO_8859_5, "ISO_8859_5" },
+ { ISO_8859_6, "ISO_8859_6" },
+ { ISO_8859_7, "ISO_8859_7" },
+ { ISO_8859_8, "ISO_8859_8" },
+ { ISO_8859_9, "ISO_8859_9" },
+ { ISO_8859_10, "ISO_8859_10" },
+ { ISO_8859_11, "ISO_8859_11" },
+ { ISO_8859_13, "ISO_8859_13" },
+ { ISO_8859_14, "ISO_8859_14" },
+ { ISO_8859_15, "ISO_8859_15" },
+ { ISO_8859_16, "ISO_8859_16" },
+ { KOI8, "KOI8" },
+ { KOI8_R, "KOI8_R" }
+};
+
+
+static int IsAlpha(int enc, int c)
+{
+ if (enc == ASCII)
+ return isalpha(c);
+
+ if (c >= 0x41 && c <= 0x5a) return 1;
+ if (c >= 0x61 && c <= 0x7a) return 1;
+
+ switch (enc) {
+ case UNICODE_ISO_8859_1:
+ case ISO_8859_1:
+ case ISO_8859_9:
+ if (c == 0xaa) return 1;
+ if (c == 0xb5) return 1;
+ if (c == 0xba) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xff) return 1;
+ break;
+
+ case ISO_8859_2:
+ if (c == 0xa1 || c == 0xa3) return 1;
+ if (c == 0xa5 || c == 0xa6) return 1;
+ if (c >= 0xa9 && c <= 0xac) return 1;
+ if (c >= 0xae && c <= 0xaf) return 1;
+ if (c == 0xb1 || c == 0xb3) return 1;
+ if (c == 0xb5 || c == 0xb6) return 1;
+ if (c >= 0xb9 && c <= 0xbc) return 1;
+ if (c >= 0xbe && c <= 0xbf) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_3:
+ if (c == 0xa1) return 1;
+ if (c == 0xa6) return 1;
+ if (c >= 0xa9 && c <= 0xac) return 1;
+ if (c == 0xaf) return 1;
+ if (c == 0xb1) return 1;
+ if (c == 0xb5 || c == 0xb6) return 1;
+ if (c >= 0xb9 && c <= 0xbc) return 1;
+ if (c == 0xbf) return 1;
+ if (c >= 0xc0 && c <= 0xc2) return 1;
+ if (c >= 0xc4 && c <= 0xcf) return 1;
+ if (c >= 0xd1 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xe2) return 1;
+ if (c >= 0xe4 && c <= 0xef) return 1;
+ if (c >= 0xf1 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_4:
+ if (c >= 0xa1 && c <= 0xa3) return 1;
+ if (c == 0xa5 || c == 0xa6) return 1;
+ if (c >= 0xa9 && c <= 0xac) return 1;
+ if (c == 0xae) return 1;
+ if (c == 0xb1 || c == 0xb3) return 1;
+ if (c == 0xb5 || c == 0xb6) return 1;
+ if (c >= 0xb9 && c <= 0xbf) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_5:
+ if (c >= 0xa1 && c <= 0xcf && c != 0xad) return 1;
+ if (c >= 0xd0 && c <= 0xff && c != 0xf0 && c != 0xfd) return 1;
+ break;
+
+ case ISO_8859_6:
+ if (c >= 0xc1 && c <= 0xda) return 1;
+ if (c >= 0xe0 && c <= 0xf2) return 1;
+ break;
+
+ case ISO_8859_7:
+ if (c == 0xb6) return 1;
+ if (c >= 0xb8 && c <= 0xba) return 1;
+ if (c == 0xbc) return 1;
+ if (c >= 0xbe && c <= 0xbf) return 1;
+ if (c == 0xc0) return 1;
+ if (c >= 0xc1 && c <= 0xdb && c != 0xd2) return 1;
+ if (c >= 0xdc && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_8:
+ if (c == 0xb5) return 1;
+ if (c >= 0xe0 && c <= 0xfa) return 1;
+ break;
+
+ case ISO_8859_10:
+ if (c >= 0xa1 && c <= 0xa6) return 1;
+ if (c >= 0xa8 && c <= 0xac) return 1;
+ if (c == 0xae || c == 0xaf) return 1;
+ if (c >= 0xb1 && c <= 0xb6) return 1;
+ if (c >= 0xb8 && c <= 0xbc) return 1;
+ if (c >= 0xbe && c <= 0xff) return 1;
+ break;
+
+ case ISO_8859_11:
+ if (c >= 0xa1 && c <= 0xda) return 1;
+ if (c >= 0xdf && c <= 0xfb) return 1;
+ break;
+
+ case ISO_8859_13:
+ if (c == 0xa8) return 1;
+ if (c == 0xaa) return 1;
+ if (c == 0xaf) return 1;
+ if (c == 0xb5) return 1;
+ if (c == 0xb8) return 1;
+ if (c == 0xba) return 1;
+ if (c >= 0xbf && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_14:
+ if (c == 0xa1 || c == 0xa2) return 1;
+ if (c == 0xa4 || c == 0xa5) return 1;
+ if (c == 0xa6 || c == 0xa8) return 1;
+ if (c >= 0xaa && c <= 0xac) return 1;
+ if (c >= 0xaf && c <= 0xb5) return 1;
+ if (c >= 0xb7 && c <= 0xff) return 1;
+ break;
+
+ case ISO_8859_15:
+ if (c == 0xaa) return 1;
+ if (c == 0xb5) return 1;
+ if (c == 0xba) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xff) return 1;
+ if (c == 0xa6) return 1;
+ if (c == 0xa8) return 1;
+ if (c == 0xb4) return 1;
+ if (c == 0xb8) return 1;
+ if (c == 0xbc) return 1;
+ if (c == 0xbd) return 1;
+ if (c == 0xbe) return 1;
+ break;
+
+ case ISO_8859_16:
+ if (c == 0xa1) return 1;
+ if (c == 0xa2) return 1;
+ if (c == 0xa3) return 1;
+ if (c == 0xa6) return 1;
+ if (c == 0xa8) return 1;
+ if (c == 0xaa) return 1;
+ if (c == 0xac) return 1;
+ if (c == 0xae) return 1;
+ if (c == 0xaf) return 1;
+ if (c == 0xb2) return 1;
+ if (c == 0xb3) return 1;
+ if (c == 0xb4) return 1;
+ if (c >= 0xb8 && c <= 0xba) return 1;
+ if (c == 0xbc) return 1;
+ if (c == 0xbd) return 1;
+ if (c == 0xbe) return 1;
+ if (c == 0xbf) return 1;
+ if (c >= 0xc0 && c <= 0xde) return 1;
+ if (c >= 0xdf && c <= 0xff) return 1;
+ break;
+
+ case KOI8_R:
+ if (c == 0xa3 || c == 0xb3) return 1;
+ /* fall */
+ case KOI8:
+ if (c >= 0xc0 && c <= 0xff) return 1;
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsBlank(int enc, int c)
+{
+ if (enc == ASCII)
+ return isblank(c);
+
+ if (c == 0x09 || c == 0x20) return 1;
+
+ switch (enc) {
+ case UNICODE_ISO_8859_1:
+ case ISO_8859_1:
+ case ISO_8859_2:
+ case ISO_8859_3:
+ case ISO_8859_4:
+ case ISO_8859_5:
+ case ISO_8859_6:
+ case ISO_8859_7:
+ case ISO_8859_8:
+ case ISO_8859_9:
+ case ISO_8859_10:
+ case ISO_8859_11:
+ case ISO_8859_13:
+ case ISO_8859_14:
+ case ISO_8859_15:
+ case ISO_8859_16:
+ case KOI8:
+ if (c == 0xa0) return 1;
+ break;
+
+ case KOI8_R:
+ if (c == 0x9a) return 1;
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsCntrl(int enc, int c)
+{
+ if (enc == ASCII)
+ return iscntrl(c);
+
+ if (c >= 0x00 && c <= 0x1F) return 1;
+
+ switch (enc) {
+ case UNICODE_ISO_8859_1:
+ if (c == 0xad) return 1;
+ /* fall */
+ case ISO_8859_1:
+ case ISO_8859_2:
+ case ISO_8859_3:
+ case ISO_8859_4:
+ case ISO_8859_5:
+ case ISO_8859_6:
+ case ISO_8859_7:
+ case ISO_8859_8:
+ case ISO_8859_9:
+ case ISO_8859_10:
+ case ISO_8859_11:
+ case ISO_8859_13:
+ case ISO_8859_14:
+ case ISO_8859_15:
+ case ISO_8859_16:
+ case KOI8:
+ if (c >= 0x7f && c <= 0x9F) return 1;
+ break;
+
+
+ case KOI8_R:
+ if (c == 0x7f) return 1;
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsDigit(int enc ARG_UNUSED, int c)
+{
+ if (c >= 0x30 && c <= 0x39) return 1;
+ return 0;
+}
+
+static int IsGraph(int enc, int c)
+{
+ if (enc == ASCII)
+ return isgraph(c);
+
+ if (c >= 0x21 && c <= 0x7e) return 1;
+
+ switch (enc) {
+ case UNICODE_ISO_8859_1:
+ case ISO_8859_1:
+ case ISO_8859_2:
+ case ISO_8859_4:
+ case ISO_8859_5:
+ case ISO_8859_9:
+ case ISO_8859_10:
+ case ISO_8859_13:
+ case ISO_8859_14:
+ case ISO_8859_15:
+ case ISO_8859_16:
+ if (c >= 0xa1 && c <= 0xff) return 1;
+ break;
+
+ case ISO_8859_3:
+ if (c >= 0xa1) {
+ if (c == 0xa5 || c == 0xae || c == 0xbe || c == 0xc3 || c == 0xd0 ||
+ c == 0xe3 || c == 0xf0)
+ return 0;
+ else
+ return 1;
+ }
+ break;
+
+ case ISO_8859_6:
+ if (c == 0xa4 || c == 0xac || c == 0xad || c == 0xbb || c == 0xbf)
+ return 1;
+ if (c >= 0xc1 && c <= 0xda) return 1;
+ if (c >= 0xe0 && c <= 0xf2) return 1;
+ break;
+
+ case ISO_8859_7:
+ if (c >= 0xa1 && c <= 0xfe &&
+ c != 0xa4 && c != 0xa5 && c != 0xaa &&
+ c != 0xae && c != 0xd2) return 1;
+ break;
+
+ case ISO_8859_8:
+ if (c >= 0xa2 && c <= 0xfa) {
+ if (c >= 0xbf && c <= 0xde) return 0;
+ return 1;
+ }
+ break;
+
+ case ISO_8859_11:
+ if (c >= 0xa1 && c <= 0xda) return 1;
+ if (c >= 0xdf && c <= 0xfb) return 1;
+ break;
+
+ case KOI8:
+ if (c >= 0xc0 && c <= 0xff) return 1;
+ break;
+
+ case KOI8_R:
+ if (c >= 0x80 && c <= 0xff && c != 0x9a) return 1;
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsLower(int enc, int c)
+{
+ if (enc == ASCII)
+ return islower(c);
+
+ if (c >= 0x61 && c <= 0x7a) return 1;
+
+ switch (enc) {
+ case UNICODE_ISO_8859_1:
+ case ISO_8859_1:
+ case ISO_8859_9:
+ if (c == 0xaa) return 1;
+ if (c == 0xb5) return 1;
+ if (c == 0xba) return 1;
+ if (c >= 0xdf && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xff) return 1;
+ break;
+
+ case ISO_8859_2:
+ if (c == 0xb1 || c == 0xb3) return 1;
+ if (c == 0xb5 || c == 0xb6) return 1;
+ if (c >= 0xb9 && c <= 0xbc) return 1;
+ if (c >= 0xbe && c <= 0xbf) return 1;
+ if (c >= 0xdf && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_3:
+ if (c == 0xb1) return 1;
+ if (c == 0xb5 || c == 0xb6) return 1;
+ if (c >= 0xb9 && c <= 0xbc) return 1;
+ if (c == 0xbf) return 1;
+ if (c == 0xdf) return 1;
+ if (c >= 0xe0 && c <= 0xe2) return 1;
+ if (c >= 0xe4 && c <= 0xef) return 1;
+ if (c >= 0xf1 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_4:
+ if (c == 0xa2) return 1;
+ if (c == 0xb1 || c == 0xb3) return 1;
+ if (c == 0xb5 || c == 0xb6) return 1;
+ if (c >= 0xb9 && c <= 0xbc) return 1;
+ if (c >= 0xbe && c <= 0xbf) return 1;
+ if (c == 0xdf) return 1;
+ if (c >= 0xe0 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_5:
+ if (c >= 0xd0 && c <= 0xff && c != 0xf0 && c != 0xfd) return 1;
+ break;
+
+ case ISO_8859_6:
+ break;
+
+ case ISO_8859_7:
+ if (c == 0xc0) return 1;
+ if (c >= 0xdc && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_8:
+ if (c == 0xb5) return 1;
+ break;
+
+ case ISO_8859_10:
+ if (c >= 0xb1 && c <= 0xb6) return 1;
+ if (c >= 0xb8 && c <= 0xbc) return 1;
+ if (c == 0xbe || c == 0xbf) return 1;
+ if (c >= 0xdf && c <= 0xff) return 1;
+ break;
+
+ case ISO_8859_11:
+ break;
+
+ case ISO_8859_13:
+ if (c == 0xb5) return 1;
+ if (c == 0xb8) return 1;
+ if (c == 0xba) return 1;
+ if (c == 0xbf) return 1;
+ if (c >= 0xdf && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_14:
+ if (c == 0xa2) return 1;
+ if (c == 0xa5) return 1;
+ if (c == 0xab) return 1;
+ if (c == 0xb1 || c == 0xb3 || c == 0xb5) return 1;
+ if (c >= 0xb8 && c <= 0xba) return 1;
+ if (c == 0xbc) return 1;
+ if (c == 0xbe || c == 0xbf) return 1;
+ if (c >= 0xdf && c <= 0xff) return 1;
+ break;
+
+ case ISO_8859_15:
+ if (c == 0xaa) return 1;
+ if (c == 0xb5) return 1;
+ if (c == 0xba) return 1;
+ if (c >= 0xdf && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xff) return 1;
+ if (c == 0xa8) return 1;
+ if (c == 0xb8) return 1;
+ if (c == 0xbd) return 1;
+ break;
+
+ case ISO_8859_16:
+ if (c == 0xa2) return 1;
+ if (c == 0xa8) return 1;
+ if (c == 0xae) return 1;
+ if (c == 0xb3) return 1;
+ if (c >= 0xb8 && c <= 0xba) return 1;
+ if (c == 0xbd) return 1;
+ if (c == 0xbf) return 1;
+ if (c >= 0xdf && c <= 0xff) return 1;
+ break;
+
+ case KOI8_R:
+ if (c == 0xa3) return 1;
+ /* fall */
+ case KOI8:
+ if (c >= 0xc0 && c <= 0xdf) return 1;
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsPrint(int enc, int c)
+{
+ if (enc == ASCII)
+ return isprint(c);
+
+ if (c >= 0x20 && c <= 0x7e) return 1;
+
+ switch (enc) {
+ case UNICODE_ISO_8859_1:
+ /* if (c >= 0x09 && c <= 0x0d) return 1; */
+ if (c == 0x85) return 1;
+ /* fall */
+ case ISO_8859_1:
+ case ISO_8859_2:
+ case ISO_8859_4:
+ case ISO_8859_5:
+ case ISO_8859_9:
+ case ISO_8859_10:
+ case ISO_8859_13:
+ case ISO_8859_14:
+ case ISO_8859_15:
+ case ISO_8859_16:
+ if (c >= 0xa0 && c <= 0xff) return 1;
+ break;
+
+ case ISO_8859_3:
+ if (c >= 0xa0) {
+ if (c == 0xa5 || c == 0xae || c == 0xbe || c == 0xc3 || c == 0xd0 ||
+ c == 0xe3 || c == 0xf0)
+ return 0;
+ else
+ return 1;
+ }
+ break;
+
+ case ISO_8859_6:
+ if (c == 0xa0) return 1;
+ if (c == 0xa4 || c == 0xac || c == 0xad || c == 0xbb || c == 0xbf)
+ return 1;
+ if (c >= 0xc1 && c <= 0xda) return 1;
+ if (c >= 0xe0 && c <= 0xf2) return 1;
+ break;
+
+ case ISO_8859_7:
+ if (c >= 0xa0 && c <= 0xfe &&
+ c != 0xa4 && c != 0xa5 && c != 0xaa &&
+ c != 0xae && c != 0xd2) return 1;
+ break;
+
+ case ISO_8859_8:
+ if (c >= 0xa0 && c <= 0xfa) {
+ if (c >= 0xbf && c <= 0xde) return 0;
+ if (c == 0xa1) return 0;
+ return 1;
+ }
+ break;
+
+ case ISO_8859_11:
+ if (c >= 0xa0 && c <= 0xda) return 1;
+ if (c >= 0xdf && c <= 0xfb) return 1;
+ break;
+
+ case KOI8:
+ if (c == 0xa0) return 1;
+ if (c >= 0xc0 && c <= 0xff) return 1;
+ break;
+
+ case KOI8_R:
+ if (c >= 0x80 && c <= 0xff) return 1;
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsPunct(int enc, int c)
+{
+ if (enc == ASCII)
+ return ispunct(c);
+
+ if (enc == UNICODE_ISO_8859_1) {
+ if (c == 0x24 || c == 0x2b || c == 0x5e || c == 0x60 ||
+ c == 0x7c || c == 0x7e) return 1;
+ if (c >= 0x3c && c <= 0x3e) return 1;
+ }
+
+ if (c >= 0x21 && c <= 0x2f) return 1;
+ if (c >= 0x3a && c <= 0x40) return 1;
+ if (c >= 0x5b && c <= 0x60) return 1;
+ if (c >= 0x7b && c <= 0x7e) return 1;
+
+ switch (enc) {
+ case ISO_8859_1:
+ case ISO_8859_9:
+ case ISO_8859_15:
+ if (c == 0xad) return 1;
+ /* fall */
+ case UNICODE_ISO_8859_1:
+ if (c == 0xa1) return 1;
+ if (c == 0xab) return 1;
+ if (c == 0xb7) return 1;
+ if (c == 0xbb) return 1;
+ if (c == 0xbf) return 1;
+ break;
+
+ case ISO_8859_2:
+ case ISO_8859_4:
+ case ISO_8859_5:
+ case ISO_8859_14:
+ if (c == 0xad) return 1;
+ break;
+
+ case ISO_8859_3:
+ case ISO_8859_10:
+ if (c == 0xad) return 1;
+ if (c == 0xb7) return 1;
+ if (c == 0xbd) return 1;
+ break;
+
+ case ISO_8859_6:
+ if (c == 0xac) return 1;
+ if (c == 0xad) return 1;
+ if (c == 0xbb) return 1;
+ if (c == 0xbf) return 1;
+ break;
+
+ case ISO_8859_7:
+ if (c == 0xa1 || c == 0xa2) return 1;
+ if (c == 0xab) return 1;
+ if (c == 0xaf) return 1;
+ if (c == 0xad) return 1;
+ if (c == 0xb7 || c == 0xbb) return 1;
+ break;
+
+ case ISO_8859_8:
+ if (c == 0xab) return 1;
+ if (c == 0xad) return 1;
+ if (c == 0xb7) return 1;
+ if (c == 0xbb) return 1;
+ if (c == 0xdf) return 1;
+ break;
+
+ case ISO_8859_13:
+ if (c == 0xa1 || c == 0xa5) return 1;
+ if (c == 0xab || c == 0xad) return 1;
+ if (c == 0xb4 || c == 0xb7) return 1;
+ if (c == 0xbb) return 1;
+ if (c == 0xff) return 1;
+ break;
+
+ case ISO_8859_16:
+ if (c == 0xa5) return 1;
+ if (c == 0xab) return 1;
+ if (c == 0xad) return 1;
+ if (c == 0xb5) return 1;
+ if (c == 0xb7) return 1;
+ if (c == 0xbb) return 1;
+ break;
+
+ case KOI8_R:
+ if (c == 0x9e) return 1;
+ break;
+
+ case ISO_8859_11:
+ case KOI8:
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsSpace(int enc, int c)
+{
+ if (enc == ASCII)
+ return isspace(c);
+
+ if (c >= 0x09 && c <= 0x0d) return 1;
+ if (c == 0x20) return 1;
+
+ switch (enc) {
+ case UNICODE_ISO_8859_1:
+ if (c == 0x85) return 1;
+ /* fall */
+ case ISO_8859_1:
+ case ISO_8859_2:
+ case ISO_8859_3:
+ case ISO_8859_4:
+ case ISO_8859_5:
+ case ISO_8859_6:
+ case ISO_8859_7:
+ case ISO_8859_8:
+ case ISO_8859_9:
+ case ISO_8859_10:
+ case ISO_8859_11:
+ case ISO_8859_13:
+ case ISO_8859_14:
+ case ISO_8859_15:
+ case ISO_8859_16:
+ case KOI8:
+ if (c == 0xa0) return 1;
+ break;
+
+ case KOI8_R:
+ if (c == 0x9a) return 1;
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsUpper(int enc, int c)
+{
+ if (enc == ASCII)
+ return isupper(c);
+
+ if (c >= 0x41 && c <= 0x5a) return 1;
+
+ switch (enc) {
+ case UNICODE_ISO_8859_1:
+ case ISO_8859_1:
+ case ISO_8859_9:
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xde) return 1;
+ break;
+
+ case ISO_8859_2:
+ if (c == 0xa1 || c == 0xa3) return 1;
+ if (c == 0xa5 || c == 0xa6) return 1;
+ if (c >= 0xa9 && c <= 0xac) return 1;
+ if (c >= 0xae && c <= 0xaf) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xde) return 1;
+ break;
+
+ case ISO_8859_3:
+ if (c == 0xa1) return 1;
+ if (c == 0xa6) return 1;
+ if (c >= 0xa9 && c <= 0xac) return 1;
+ if (c == 0xaf) return 1;
+ if (c >= 0xc0 && c <= 0xc2) return 1;
+ if (c >= 0xc4 && c <= 0xcf) return 1;
+ if (c >= 0xd1 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xde) return 1;
+ break;
+
+ case ISO_8859_4:
+ if (c == 0xa1 || c == 0xa3) return 1;
+ if (c == 0xa5 || c == 0xa6) return 1;
+ if (c >= 0xa9 && c <= 0xac) return 1;
+ if (c == 0xae) return 1;
+ if (c == 0xbd) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xde) return 1;
+ break;
+
+ case ISO_8859_5:
+ if (c >= 0xa1 && c <= 0xcf && c != 0xad) return 1;
+ break;
+
+ case ISO_8859_6:
+ break;
+
+ case ISO_8859_7:
+ if (c == 0xb6) return 1;
+ if (c >= 0xb8 && c <= 0xba) return 1;
+ if (c == 0xbc) return 1;
+ if (c >= 0xbe && c <= 0xbf) return 1;
+ if (c >= 0xc1 && c <= 0xdb && c != 0xd2) return 1;
+ break;
+
+ case ISO_8859_8:
+ case ISO_8859_11:
+ break;
+
+ case ISO_8859_10:
+ if (c >= 0xa1 && c <= 0xa6) return 1;
+ if (c >= 0xa8 && c <= 0xac) return 1;
+ if (c == 0xae || c == 0xaf) return 1;
+ if (c >= 0xc0 && c <= 0xde) return 1;
+ break;
+
+ case ISO_8859_13:
+ if (c == 0xa8) return 1;
+ if (c == 0xaa) return 1;
+ if (c == 0xaf) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xde) return 1;
+ break;
+
+ case ISO_8859_14:
+ if (c == 0xa1) return 1;
+ if (c == 0xa4 || c == 0xa6) return 1;
+ if (c == 0xa8) return 1;
+ if (c == 0xaa || c == 0xac) return 1;
+ if (c == 0xaf || c == 0xb0) return 1;
+ if (c == 0xb2 || c == 0xb4 || c == 0xb7) return 1;
+ if (c == 0xbb || c == 0xbd) return 1;
+ if (c >= 0xc0 && c <= 0xde) return 1;
+ break;
+
+ case ISO_8859_15:
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xde) return 1;
+ if (c == 0xa6) return 1;
+ if (c == 0xb4) return 1;
+ if (c == 0xbc) return 1;
+ if (c == 0xbe) return 1;
+ break;
+
+ case ISO_8859_16:
+ if (c == 0xa1) return 1;
+ if (c == 0xa3) return 1;
+ if (c == 0xa6) return 1;
+ if (c == 0xaa) return 1;
+ if (c == 0xac) return 1;
+ if (c == 0xaf) return 1;
+ if (c == 0xb2) return 1;
+ if (c == 0xb4) return 1;
+ if (c == 0xbc) return 1;
+ if (c == 0xbe) return 1;
+ if (c >= 0xc0 && c <= 0xde) return 1;
+ break;
+
+ case KOI8_R:
+ if (c == 0xb3) return 1;
+ /* fall */
+ case KOI8:
+ if (c >= 0xe0 && c <= 0xff) return 1;
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsXDigit(int enc, int c)
+{
+ if (enc == ASCII)
+ return isxdigit(c);
+
+ if (c >= 0x30 && c <= 0x39) return 1;
+ if (c >= 0x41 && c <= 0x46) return 1;
+ if (c >= 0x61 && c <= 0x66) return 1;
+ return 0;
+}
+
+static int IsWord(int enc, int c)
+{
+ if (enc == ASCII) {
+ return (isalpha(c) || isdigit(c) || c == 0x5f);
+ }
+
+ if (c >= 0x30 && c <= 0x39) return 1;
+ if (c >= 0x41 && c <= 0x5a) return 1;
+ if (c == 0x5f) return 1;
+ if (c >= 0x61 && c <= 0x7a) return 1;
+
+ switch (enc) {
+ case UNICODE_ISO_8859_1:
+ case ISO_8859_1:
+ case ISO_8859_9:
+ if (c == 0xaa) return 1;
+ if (c >= 0xb2 && c <= 0xb3) return 1;
+ if (c == 0xb5) return 1;
+ if (c >= 0xb9 && c <= 0xba) return 1;
+ if (c >= 0xbc && c <= 0xbe) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xff) return 1;
+ break;
+
+ case ISO_8859_2:
+ if (c == 0xa1 || c == 0xa3) return 1;
+ if (c == 0xa5 || c == 0xa6) return 1;
+ if (c >= 0xa9 && c <= 0xac) return 1;
+ if (c >= 0xae && c <= 0xaf) return 1;
+ if (c == 0xb1 || c == 0xb3) return 1;
+ if (c == 0xb5 || c == 0xb6) return 1;
+ if (c >= 0xb9 && c <= 0xbc) return 1;
+ if (c >= 0xbe && c <= 0xbf) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_3:
+ if (c == 0xa1) return 1;
+ if (c == 0xa6) return 1;
+ if (c >= 0xa9 && c <= 0xac) return 1;
+ if (c == 0xaf) return 1;
+ if (c >= 0xb1 && c <= 0xb3) return 1;
+ if (c == 0xb5 || c == 0xb6) return 1;
+ if (c >= 0xb9 && c <= 0xbd) return 1;
+ if (c == 0xbf) return 1;
+ if (c >= 0xc0 && c <= 0xc2) return 1;
+ if (c >= 0xc4 && c <= 0xcf) return 1;
+ if (c >= 0xd1 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xe2) return 1;
+ if (c >= 0xe4 && c <= 0xef) return 1;
+ if (c >= 0xf1 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_4:
+ if (c >= 0xa1 && c <= 0xa3) return 1;
+ if (c == 0xa5 || c == 0xa6) return 1;
+ if (c >= 0xa9 && c <= 0xac) return 1;
+ if (c == 0xae) return 1;
+ if (c == 0xb1 || c == 0xb3) return 1;
+ if (c == 0xb5 || c == 0xb6) return 1;
+ if (c >= 0xb9 && c <= 0xbf) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_5:
+ if (c >= 0xa1 && c <= 0xcf && c != 0xad) return 1;
+ if (c >= 0xd0 && c <= 0xff && c != 0xf0 && c != 0xfd) return 1;
+ break;
+
+ case ISO_8859_6:
+ if (c >= 0xc1 && c <= 0xda) return 1;
+ if (c >= 0xe0 && c <= 0xea) return 1;
+ if (c >= 0xeb && c <= 0xf2) return 1;
+ break;
+
+ case ISO_8859_7:
+ if (c == 0xb2 || c == 0xb3) return 1;
+ if (c == 0xb6) return 1;
+ if (c >= 0xb8 && c <= 0xba) return 1;
+ if (c >= 0xbc && c <= 0xbf) return 1;
+ if (c == 0xc0) return 1;
+ if (c >= 0xc1 && c <= 0xdb && c != 0xd2) return 1;
+ if (c >= 0xdc && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_8:
+ if (c == 0xb2 || c == 0xb3 || c == 0xb5 || c == 0xb9) return 1;
+ if (c >= 0xbc && c <= 0xbe) return 1;
+ if (c >= 0xe0 && c <= 0xfa) return 1;
+ break;
+
+ case ISO_8859_10:
+ if (c >= 0xa1 && c <= 0xff) {
+ if (c != 0xa7 && c != 0xad && c != 0xb0 && c != 0xb7 && c != 0xbd)
+ return 1;
+ }
+ break;
+
+ case ISO_8859_11:
+ if (c >= 0xa1 && c <= 0xda) return 1;
+ if (c >= 0xdf && c <= 0xfb) return 1;
+ break;
+
+ case ISO_8859_13:
+ if (c == 0xa8) return 1;
+ if (c == 0xaa) return 1;
+ if (c == 0xaf) return 1;
+ if (c == 0xb2 || c == 0xb3 || c == 0xb5 || c == 0xb9) return 1;
+ if (c >= 0xbc && c <= 0xbe) return 1;
+ if (c == 0xb8) return 1;
+ if (c == 0xba) return 1;
+ if (c >= 0xbf && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xfe) return 1;
+ break;
+
+ case ISO_8859_14:
+ if (c >= 0xa1 && c <= 0xff) {
+ if (c == 0xa3 || c == 0xa7 || c == 0xa9 || c == 0xad || c == 0xae ||
+ c == 0xb6) return 0;
+ return 1;
+ }
+ break;
+
+ case ISO_8859_15:
+ if (c == 0xaa) return 1;
+ if (c >= 0xb2 && c <= 0xb3) return 1;
+ if (c == 0xb5) return 1;
+ if (c >= 0xb9 && c <= 0xba) return 1;
+ if (c >= 0xbc && c <= 0xbe) return 1;
+ if (c >= 0xc0 && c <= 0xd6) return 1;
+ if (c >= 0xd8 && c <= 0xf6) return 1;
+ if (c >= 0xf8 && c <= 0xff) return 1;
+ if (c == 0xa6) return 1;
+ if (c == 0xa8) return 1;
+ if (c == 0xb4) return 1;
+ if (c == 0xb8) return 1;
+ break;
+
+ case ISO_8859_16:
+ if (c == 0xa1) return 1;
+ if (c == 0xa2) return 1;
+ if (c == 0xa3) return 1;
+ if (c == 0xa6) return 1;
+ if (c == 0xa8) return 1;
+ if (c == 0xaa) return 1;
+ if (c == 0xac) return 1;
+ if (c == 0xae) return 1;
+ if (c == 0xaf) return 1;
+ if (c == 0xb2) return 1;
+ if (c == 0xb3) return 1;
+ if (c == 0xb4) return 1;
+ if (c >= 0xb8 && c <= 0xba) return 1;
+ if (c == 0xbc) return 1;
+ if (c == 0xbd) return 1;
+ if (c == 0xbe) return 1;
+ if (c == 0xbf) return 1;
+ if (c >= 0xc0 && c <= 0xde) return 1;
+ if (c >= 0xdf && c <= 0xff) return 1;
+ break;
+
+ case KOI8_R:
+ if (c == 0x9d) return 1;
+ if (c == 0xa3 || c == 0xb3) return 1;
+ /* fall */
+ case KOI8:
+ if (c >= 0xc0 && c <= 0xff) return 1;
+ break;
+
+ default:
+ exit(-1);
+ }
+
+ return 0;
+}
+
+static int IsAscii(int enc ARG_UNUSED, int c)
+{
+ if (c >= 0x00 && c <= 0x7f) return 1;
+ return 0;
+}
+
+static int IsNewline(int enc ARG_UNUSED, int c)
+{
+ if (c == 0x0a) return 1;
+ return 0;
+}
+
+static int exec(FILE* fp, ENC_INFO* einfo)
+{
+#define NCOL 8
+
+ int c, val, enc;
+
+ enc = einfo->num;
+
+ fprintf(fp, "static const unsigned short Enc%s_CtypeTable[256] = {\n",
+ einfo->name);
+
+ for (c = 0; c < 256; c++) {
+ val = 0;
+ if (IsNewline(enc, c)) val |= BIT_CTYPE_NEWLINE;
+ if (IsAlpha (enc, c)) val |= (BIT_CTYPE_ALPHA | BIT_CTYPE_ALNUM);
+ if (IsBlank (enc, c)) val |= BIT_CTYPE_BLANK;
+ if (IsCntrl (enc, c)) val |= BIT_CTYPE_CNTRL;
+ if (IsDigit (enc, c)) val |= (BIT_CTYPE_DIGIT | BIT_CTYPE_ALNUM);
+ if (IsGraph (enc, c)) val |= BIT_CTYPE_GRAPH;
+ if (IsLower (enc, c)) val |= BIT_CTYPE_LOWER;
+ if (IsPrint (enc, c)) val |= BIT_CTYPE_PRINT;
+ if (IsPunct (enc, c)) val |= BIT_CTYPE_PUNCT;
+ if (IsSpace (enc, c)) val |= BIT_CTYPE_SPACE;
+ if (IsUpper (enc, c)) val |= BIT_CTYPE_UPPER;
+ if (IsXDigit(enc, c)) val |= BIT_CTYPE_XDIGIT;
+ if (IsWord (enc, c)) val |= BIT_CTYPE_WORD;
+ if (IsAscii (enc, c)) val |= BIT_CTYPE_ASCII;
+
+ if (c % NCOL == 0) fputs(" ", fp);
+ fprintf(fp, "0x%04x", val);
+ if (c != 255) fputs(",", fp);
+ if (c != 0 && c % NCOL == (NCOL-1))
+ fputs("\n", fp);
+ else
+ fputs(" ", fp);
+ }
+ fprintf(fp, "};\n");
+ return 0;
+}
+
+extern int main(int argc ARG_UNUSED, char* argv[] ARG_UNUSED)
+{
+ int i;
+ FILE* fp = stdout;
+
+ setlocale(LC_ALL, "C");
+ /* setlocale(LC_ALL, "POSIX"); */
+ /* setlocale(LC_ALL, "en_GB.iso88591"); */
+ /* setlocale(LC_ALL, "de_BE.iso88591"); */
+ /* setlocale(LC_ALL, "fr_FR.iso88591"); */
+
+ for (i = 0; i < (int )(sizeof(Info)/sizeof(ENC_INFO)); i++) {
+ exec(fp, &Info[i]);
+ }
+
+ return 0;
+}
View
280 enc/shift_jis.c
@@ -1,8 +1,9 @@
/**********************************************************************
- sjis.c - Oniguruma (regular expression library)
+ sjis.c - Onigmo (Oniguruma-mod) (regular expression library)
**********************************************************************/
/*-
* Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
+ * Copyright (c) 2011 K.Takata <kentkt AT csc DOT jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -67,6 +68,97 @@ static const char SJIS_CAN_BE_TRAIL_TABLE[256] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
};
+static const OnigPairCaseFoldCodes CaseFoldMap[] = {
+ /* Fullwidth Alphabet */
+ { 0x8260, 0x8281 },
+ { 0x8261, 0x8282 },
+ { 0x8262, 0x8283 },
+ { 0x8263, 0x8284 },
+ { 0x8264, 0x8285 },
+ { 0x8265, 0x8286 },
+ { 0x8266, 0x8287 },
+ { 0x8267, 0x8288 },
+ { 0x8268, 0x8289 },
+ { 0x8269, 0x828a },
+ { 0x826a, 0x828b },
+ { 0x826b, 0x828c },
+ { 0x826c, 0x828d },
+ { 0x826d, 0x828e },
+ { 0x826e, 0x828f },
+ { 0x826f, 0x8290 },
+ { 0x8270, 0x8291 },
+ { 0x8271, 0x8292 },
+ { 0x8272, 0x8293 },
+ { 0x8273, 0x8294 },
+ { 0x8274, 0x8295 },
+ { 0x8275, 0x8296 },
+ { 0x8276, 0x8297 },
+ { 0x8277, 0x8298 },
+ { 0x8278, 0x8299 },
+ { 0x8279, 0x829a },
+
+ /* Greek */
+ { 0x839f, 0x83bf },
+ { 0x83a0, 0x83c0 },
+ { 0x83a1, 0x83c1 },
+ { 0x83a2, 0x83c2 },
+ { 0x83a3, 0x83c3 },
+ { 0x83a4, 0x83c4 },
+ { 0x83a5, 0x83c5 },
+ { 0x83a6, 0x83c6 },
+ { 0x83a7, 0x83c7 },
+ { 0x83a8, 0x83c8 },
+ { 0x83a9, 0x83c9 },
+ { 0x83aa, 0x83ca },
+ { 0x83ab, 0x83cb },
+ { 0x83ac, 0x83cc },
+ { 0x83ad, 0x83cd },
+ { 0x83ae, 0x83ce },
+ { 0x83af, 0x83cf },
+ { 0x83b0, 0x83d0 },
+ { 0x83b1, 0x83d1 },
+ { 0x83b2, 0x83d2 },
+ { 0x83b3, 0x83d3 },
+ { 0x83b4, 0x83d4 },
+ { 0x83b5, 0x83d5 },
+ { 0x83b6, 0x83d6 },
+
+ /* Cyrillic */
+ { 0x8440, 0x8470 },
+ { 0x8441, 0x8471 },
+ { 0x8442, 0x8472 },
+ { 0x8443, 0x8473 },
+ { 0x8444, 0x8474 },
+ { 0x8445, 0x8475 },
+ { 0x8446, 0x8476 },
+ { 0x8447, 0x8477 },
+ { 0x8448, 0x8478 },
+ { 0x8449, 0x8479 },
+ { 0x844a, 0x847a },
+ { 0x844b, 0x847b },
+ { 0x844c, 0x847c },
+ { 0x844d, 0x847d },
+ { 0x844e, 0x847e },
+ { 0x844f, 0x8480 },
+ { 0x8450, 0x8481 },
+ { 0x8451, 0x8482 },
+ { 0x8452, 0x8483 },
+ { 0x8453, 0x8484 },
+ { 0x8454, 0x8485 },
+ { 0x8455, 0x8486 },
+ { 0x8456, 0x8487 },
+ { 0x8457, 0x8488 },
+ { 0x8458, 0x8489 },
+ { 0x8459, 0x848a },
+ { 0x845a, 0x848b },
+ { 0x845b, 0x848c },
+ { 0x845c, 0x848d },
+ { 0x845d, 0x848e },
+ { 0x845e, 0x848f },
+ { 0x845f, 0x8490 },
+ { 0x8460, 0x8491 },
+};
+
#define SJIS_ISMB_FIRST(byte) (EncLen_SJIS[byte] > 1)
#define SJIS_ISMB_TRAIL(byte) SJIS_CAN_BE_TRAIL_TABLE[(byte)]
@@ -150,7 +242,7 @@ mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
int c, i, len;
OnigCodePoint n;
- len = enclen(enc, p, end);
+ len = mbc_enc_len(p, end, enc);
c = *p++;
n = c;
if (len == 1) return n;
@@ -172,10 +264,90 @@ code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
*p++ = (UChar )(code & 0xff);
#if 0
- if (enclen(enc, buf) != (p - buf))
+ if (mbc_enc_len(buf, p, enc) != (p - buf))
return REGERR_INVALID_CODE_POINT_VALUE;
#endif
- return (int)(p - buf);
+ return (int )(p - buf);
+}
+
+static int
+apply_all_case_fold(OnigCaseFoldType flag,
+ OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc)
+{
+ return onigenc_apply_all_case_fold_with_map(
+ sizeof(CaseFoldMap)/sizeof(OnigPairCaseFoldCodes), CaseFoldMap, 0,
+ flag, f, arg);
+}
+
+static OnigCodePoint
+get_lower_case(OnigCodePoint code)
+{
+ if (ONIGENC_IS_IN_RANGE(code, 0x8260, 0x8279)) {
+ /* Fullwidth Alphabet */
+ return (OnigCodePoint )(code + 0x0021);
+ }
+ else if (ONIGENC_IS_IN_RANGE(code, 0x839f, 0x83b6)) {
+ /* Greek */
+ return (OnigCodePoint )(code + 0x0020);
+ }
+ else if (ONIGENC_IS_IN_RANGE(code, 0x8440, 0x8460)) {
+ /* Cyrillic */
+ int d = (code >= 0x844f) ? 1 : 0;
+ return (OnigCodePoint )(code + (0x0030 + d));
+ }
+ return code;
+}
+
+static OnigCodePoint
+get_upper_case(OnigCodePoint code)
+{
+ if (ONIGENC_IS_IN_RANGE(code, 0x8281, 0x829a)) {
+ /* Fullwidth Alphabet */
+ return (OnigCodePoint )(code - 0x0021);
+ }
+ else if (ONIGENC_IS_IN_RANGE(code, 0x83bf, 0x83d6)) {
+ /* Greek */
+ return (OnigCodePoint )(code - 0x0020);
+ }
+ else if (ONIGENC_IS_IN_RANGE(code, 0x8470, 0x847e) ||
+ ONIGENC_IS_IN_RANGE(code, 0x8480, 0x8491)) {
+ /* Cyrillic */
+ int d = (code >= 0x8480) ? 1 : 0;
+ return (OnigCodePoint )(code - (0x0030 - d));
+ }
+ return code;
+}
+
+static int
+get_case_fold_codes_by_str(OnigCaseFoldType flag,
+ const OnigUChar* p, const OnigUChar* end,
+ OnigCaseFoldCodeItem items[], OnigEncoding enc)
+{
+ int len;
+ OnigCodePoint code, code_lo, code_up;
+
+ code = mbc_to_code(p, end, enc);
+ if (ONIGENC_IS_ASCII_CODE(code))
+ return onigenc_ascii_get_case_fold_codes_by_str(flag, p, end, items, enc);
+
+ len = mbc_enc_len(p, end, enc);
+ code_lo = get_lower_case(code);
+ code_up = get_upper_case(code);
+
+ if (code != code_lo) {
+ items[0].byte_len = len;
+ items[0].code_len = 1;
+ items[0].code[0] = code_lo;
+ return 1;
+ }
+ else if (code != code_up) {
+ items[0].byte_len = len;
+ items[0].code_len = 1;
+ items[0].code[0] = code_up;
+ return 1;
+ }
+
+ return 0;
}
static int
@@ -191,12 +363,11 @@ mbc_case_fold(OnigCaseFoldType flag,
return 1;
}
else {
- int i;
- int len = enclen(enc, p, end);
+ OnigCodePoint code;
+ int len;
- for (i = 0; i < len; i++) {
- *lower++ = *p++;
- }
+ code = get_lower_case(mbc_to_code(p, end, enc));
+ len = code_to_mbc(code, lower, enc);
(*pp) += len;
return len; /* return byte length of converted char to lower */
}
@@ -245,7 +416,7 @@ left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, Onig
}
}
}
- len = enclen(enc, p, end);
+ len = mbc_enc_len(p, end, enc);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
@@ -278,6 +449,47 @@ static const OnigCodePoint CR_Katakana[] = {
0x8380, 0x8396,
}; /* CR_Katakana */
+#ifdef ENC_CP932
+static const OnigCodePoint CR_Han[] = {
+ 6,
+ 0x8157, 0x8157,
+ 0x889f, 0x9872, /* Kanji level 1 */
+ 0x989f, 0x9ffc, /* Kanji level 2 */
+ 0xe040, 0xeaa4, /* Kanji level 2 */
+ 0xed40, 0xeeec, /* NEC-selected IBM extended characters (without symbols) */
+ 0xfa5c, 0xfc4b, /* IBM extended characters (without symbols) */
+}; /* CR_Han */
+#else
+static const OnigCodePoint CR_Han[] = {
+ 4,
+ 0x8157, 0x8157,
+ 0x889f, 0x9872, /* Kanji level 1 */
+ 0x989f, 0x9ffc, /* Kanji level 2 */
+ 0xe040, 0xeaa4, /* Kanji level 2 */
+}; /* CR_Han */
+#endif
+
+static const OnigCodePoint CR_Latin[] = {
+ 4,
+ 0x0041, 0x005a,
+ 0x0061, 0x007a,
+ 0x8260, 0x8279,
+ 0x8281, 0x829a,
+}; /* CR_Latin */
+
+static const OnigCodePoint CR_Greek[] = {
+ 2,
+ 0x839f, 0x83b6,
+ 0x83bf, 0x83d6,
+}; /* CR_Greek */
+
+static const OnigCodePoint CR_Cyrillic[] = {
+ 3,
+ 0x8440, 0x8460,
+ 0x8470, 0x847f,
+ 0x8480, 0x8491,
+}; /* CR_Cyrillic */
+
static int
init_property_list(void)
{
@@ -285,6 +497,10 @@ init_property_list(void)
PROPERTY_LIST_ADD_PROP("hiragana", CR_Hiragana);
PROPERTY_LIST_ADD_PROP("katakana", CR_Katakana);
+ PROPERTY_LIST_ADD_PROP("han", CR_Han);
+ PROPERTY_LIST_ADD_PROP("latin", CR_Latin);
+ PROPERTY_LIST_ADD_PROP("greek", CR_Greek);
+ PROPERTY_LIST_ADD_PROP("cyrillic", CR_Cyrillic);
PropertyInited = 1;
end:
@@ -308,7 +524,7 @@ property_name_to_ctype(OnigEncoding enc, UChar* p, UChar* end)
return onigenc_minimum_property_name_to_ctype(enc, s, e);
}
- return (int)ctype;
+ return (int )ctype;
}
static int
@@ -357,6 +573,7 @@ get_ctype_code_range(OnigCtype ctype, OnigCodePoint* sb_out,
}
}
+#ifndef ENC_CP932
OnigEncodingDefine(shift_jis, Shift_JIS) = {
mbc_enc_len,
"Shift_JIS", /* name */
@@ -367,54 +584,22 @@ OnigEncodingDefine(shift_jis, Shift_JIS) = {
code_to_mbclen,
code_to_mbc,
mbc_case_fold,
- onigenc_ascii_apply_all_case_fold,
- onigenc_ascii_get_case_fold_codes_by_str,
+ apply_all_case_fold,
+ get_case_fold_codes_by_str,
property_name_to_ctype,
is_code_ctype,
get_ctype_code_range,
left_adjust_char_head,
is_allowed_reverse_match,
- 0
+ 0,
+ ONIGENC_FLAG_NONE,
};
/*
* Name: Shift_JIS
* MIBenum: 17
* Link: http://www.iana.org/assignments/character-sets
* Link: http://ja.wikipedia.org/wiki/Shift_JIS
- *
- * Note that this Shift_JIS's 7bit part is US-ASCII not JIX X 0201
- * because Shift_JIS must be ASCII compatible encoding.
- * See also the conversion table (enc/trans/japanese_sjis.trans).
- */
-
-/*
- * Name: Windows-31J
- * MIBenum: 2024
- * Link: http://www.iana.org/assignments/character-sets
- * Link: http://www.microsoft.com/globaldev/reference/dbcs/932.mspx
- * Link: http://ja.wikipedia.org/wiki/Windows-31J
- * Link: http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/windows-932-2000.ucm
- *
- * Windows Standard Character Set and its mapping to Unicode by Microsoft.
- * Since 1.9.3, SJIS is the alias of Windows-31J because its character
- * set is usually this one even if its mapping may differ.
- */
-ENC_REPLICATE("Windows-31J", "Shift_JIS")
-ENC_ALIAS("CP932", "Windows-31J")
-ENC_ALIAS("csWindows31J", "Windows-31J") /* IANA. IE6 don't accept Windows-31J but csWindows31J. */
-ENC_ALIAS("SJIS", "Windows-31J")
-
-/*
- * Name: PCK
- * Link: http://download.oracle.com/docs/cd/E19253-01/819-0606/x-2chn0/index.html
- * Link: http://download.oracle.com/docs/cd/E19253-01/819-0606/appb-pckwarn-1/index.html
- *
- * Solaris's SJIS variant. Its set is Windows Standard Character Set; it
- * consists JIS X 0201 Latin (US-ASCII), JIS X 0201 Katakana, JIS X 0208, NEC
- * special characters, NEC-selected IBM extended characters, and IBM extended
- * characters. Solaris's iconv seems to use SJIS-open.
*/
-ENC_ALIAS("PCK", "Windows-31J")
/*
* Name: MacJapanese
@@ -423,3 +608,4 @@ ENC_ALIAS("PCK", "Windows-31J")
*/
ENC_REPLICATE("MacJapanese", "Shift_JIS")
ENC_ALIAS("MacJapan", "MacJapanese")
+#endif