diff options
author | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-07-26 06:30:39 +0000 |
---|---|---|
committer | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-07-26 06:30:39 +0000 |
commit | c8a1d8b33bc612e6c58e3fbeb3226375bc4f4184 (patch) | |
tree | d61734fc54466bb179cffb3763974102a7ca60e1 | |
parent | 18440efa3af1719fee43b8a4184a3a0e5b09ffee (diff) | |
download | ruby-c8a1d8b33bc612e6c58e3fbeb3226375bc4f4184.tar.gz |
* enc/windows_1251.c, test/ruby/enc/test_case_comprehensive.rb:
Implement non-ASCII case conversion for Windows-1251, by Shunsuke Sato.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | enc/windows_1251.c | 43 | ||||
-rw-r--r-- | test/ruby/enc/test_case_comprehensive.rb | 2 |
3 files changed, 48 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Tue Jul 26 15:30:37 2016 Martin Duerst <duerst@it.aoyama.ac.jp> + + * enc/windows_1251.c, test/ruby/enc/test_case_comprehensive.rb: + Implement non-ASCII case conversion for Windows-1251, by Shunsuke Sato. + Tue Jul 26 13:04:59 2016 Martin Duerst <duerst@it.aoyama.ac.jp> * test/ruby/enc/test_case_comprehensive.rb: Add explicit skip test for diff --git a/enc/windows_1251.c b/enc/windows_1251.c index b9675cfd8e..0f9b7fa69a 100644 --- a/enc/windows_1251.c +++ b/enc/windows_1251.c @@ -180,6 +180,47 @@ cp1251_get_case_fold_codes_by_str(OnigCaseFoldType flag, flag, p, end, items); } +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 ((EncCP1251_CtypeTable[code] & BIT_CTYPE_UPPER) + && (flags & (ONIGENC_CASE_DOWNCASE|ONIGENC_CASE_FOLD))) { + flags |= ONIGENC_CASE_MODIFIED; + code = ENC_CP1251_TO_LOWER_CASE(code); + } + else if (code==0xB5) ; + else if ((EncCP1251_CtypeTable[code]&BIT_CTYPE_LOWER) + && (flags&ONIGENC_CASE_UPCASE)) { + flags |= ONIGENC_CASE_MODIFIED; + if ((0x61<=code && code<=0x7A) || (0xE0<=code && code<=0xFF)) + code -= 0x20; + else if (code==0xA2 || code==0xB3 || code==0xBE) + code -= 0x01; + else if (code==0x83) + code = 0x81; + else if (code==0xBC) + code = 0xA3; + else if (code==0xB4) + code = 0xA5; + else + code -= 0x10; + } + *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); +} + OnigEncodingDefine(windows_1251, Windows_1251) = { onigenc_single_byte_mbc_enc_len, "Windows-1251", /* name */ @@ -199,7 +240,7 @@ OnigEncodingDefine(windows_1251, Windows_1251) = { onigenc_always_true_is_allowed_reverse_match, 0, ONIGENC_FLAG_NONE, - onigenc_single_byte_ascii_only_case_map, + case_map, }; /* * Name: windows-1251 diff --git a/test/ruby/enc/test_case_comprehensive.rb b/test/ruby/enc/test_case_comprehensive.rb index 13c61ba7d5..dabe727423 100644 --- a/test/ruby/enc/test_case_comprehensive.rb +++ b/test/ruby/enc/test_case_comprehensive.rb @@ -287,7 +287,7 @@ TestComprehensiveCaseFold.data_files_available? and class TestComprehensiveCase generate_ascii_only_case_mapping_tests 'Shift_JIS' generate_ascii_only_case_mapping_tests 'Windows-31J' generate_ascii_only_case_mapping_tests 'Windows-1250' - generate_ascii_only_case_mapping_tests 'Windows-1251' + generate_case_mapping_tests 'Windows-1251' generate_case_mapping_tests 'Windows-1252' generate_ascii_only_case_mapping_tests 'Windows-1253' generate_ascii_only_case_mapping_tests 'Windows-1254' |