diff options
author | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-07-13 09:09:47 +0000 |
---|---|---|
committer | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-07-13 09:09:47 +0000 |
commit | be72888d3d4aae3613b189090df7868afbf42a86 (patch) | |
tree | 4ce21f007c86f0c509ed804e7c876420d2b206cd /enc/iso_8859_9.c | |
parent | 9ac1d433e5a3dddb2e8ab85cd924d2435e40ed66 (diff) | |
download | ruby-be72888d3d4aae3613b189090df7868afbf42a86.tar.gz |
* enc/iso_8859_9.c, test/ruby/enc/test_case_comprehensive.rb:
Implement non-ASCII case conversion for ISO-8859-9, by Kazuki Iijima.
* enc/iso_8859_9.c: Exclude dotless i/I with dot from case-insensitive
matching because they are not a case pair.
* test/ruby/enc/test_iso_8859.rb: Make test coverage for ISO-8859-9
a bit more complete.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enc/iso_8859_9.c')
-rw-r--r-- | enc/iso_8859_9.c | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/enc/iso_8859_9.c b/enc/iso_8859_9.c index 668168daa9..5b80ebe0fe 100644 --- a/enc/iso_8859_9.c +++ b/enc/iso_8859_9.c @@ -62,7 +62,7 @@ static const UChar EncISO_8859_9_ToLowerCaseTable[256] = { '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\327', - '\370', '\371', '\372', '\373', '\374', '\335', '\376', '\337', + '\370', '\371', '\372', '\373', '\374', '\151', '\376', '\337', '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', @@ -188,7 +188,7 @@ static const OnigPairCaseFoldCodes CaseFoldMap[] = { { 0xda, 0xfa }, { 0xdb, 0xfb }, { 0xdc, 0xfc }, - { 0xdd, 0xfd }, + /*{ 0xdd, 0xfd }, exclude dotless i/I with dot; not a case pair */ { 0xde, 0xfe } }; @@ -213,6 +213,60 @@ get_case_fold_codes_by_str(OnigCaseFoldType flag, flag, p, end, items); } +#ifdef ONIG_CASE_MAPPING +#define DOTLESS_i (0xFD) +#define I_WITH_DOT_ABOVE (0xDD) +static int +case_map (OnigCaseFoldType* flagP, const OnigUChar** pp, + const OnigUChar* end, OnigUChar* to, OnigUChar* to_end, + const struct OnigEncodingTypeST* enc) +{ + OnigCodePoint code; + OnigUChar *to_start = to; + OnigCaseFoldType flags = *flagP; + + while (*pp<end && to<to_end) { + code = *(*pp)++; + if (code==SHARP_s) { + if (flags&ONIGENC_CASE_UPCASE) { + flags |= ONIGENC_CASE_MODIFIED; + *to++ = 'S'; + code = (flags&ONIGENC_CASE_TITLECASE) ? 's' : 'S'; + } + else if (flags&ONIGENC_CASE_FOLD) { + flags |= ONIGENC_CASE_MODIFIED; + *to++ = 's'; + code = 's'; + } + } + else if (code==0xAA || code==0xB5 || code==0xBA || code==0xFF) ; + else if ((EncISO_8859_9_CtypeTable[code] & BIT_CTYPE_UPPER) + && (flags & (ONIGENC_CASE_DOWNCASE|ONIGENC_CASE_FOLD))) { + flags |= ONIGENC_CASE_MODIFIED; + if (code=='I') + code = flags&ONIGENC_CASE_FOLD_TURKISH_AZERI ? DOTLESS_i : 'i'; + else + code = ENC_ISO_8859_9_TO_LOWER_CASE(code); + } + else if ((EncISO_8859_9_CtypeTable[code]&BIT_CTYPE_LOWER) + && (flags&ONIGENC_CASE_UPCASE)) { + flags |= ONIGENC_CASE_MODIFIED; + if (code=='i') + code = flags&ONIGENC_CASE_FOLD_TURKISH_AZERI ? I_WITH_DOT_ABOVE : 'I'; + else if (code==DOTLESS_i) + code = 'I'; + else + code -= 0x20; + } + *to++ = code; + if (flags&ONIGENC_CASE_TITLECASE) /* switch from titlecase to lowercase for capitalize */ + flags ^= (ONIGENC_CASE_UPCASE|ONIGENC_CASE_DOWNCASE|ONIGENC_CASE_TITLECASE); + } + *flagP = flags; + return (int)(to-to_start); +} +#endif /* ONIG_CASE_MAPPING */ + OnigEncodingDefine(iso_8859_9, ISO_8859_9) = { onigenc_single_byte_mbc_enc_len, "ISO-8859-9", /* name */ @@ -233,7 +287,7 @@ OnigEncodingDefine(iso_8859_9, ISO_8859_9) = { 0, ONIGENC_FLAG_NONE, #ifdef ONIG_CASE_MAPPING - onigenc_single_byte_ascii_only_case_map, + case_map, #endif /* ONIG_CASE_MAPPING */ }; ENC_ALIAS("ISO8859-9", "ISO-8859-9") |