ruby-changes:43593
From: duerst <ko1@a...>
Date: Wed, 13 Jul 2016 18:09:54 +0900 (JST)
Subject: [ruby-changes:43593] duerst:r55666 (trunk): * enc/iso_8859_9.c, test/ruby/enc/test_case_comprehensive.rb:
duerst 2016-07-13 18:09:47 +0900 (Wed, 13 Jul 2016) New Revision: 55666 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55666 Log: * 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. Modified files: trunk/ChangeLog trunk/enc/iso_8859_9.c trunk/test/ruby/enc/test_case_comprehensive.rb trunk/test/ruby/enc/test_iso_8859.rb Index: enc/iso_8859_9.c =================================================================== --- enc/iso_8859_9.c (revision 55665) +++ enc/iso_8859_9.c (revision 55666) @@ -62,7 +62,7 @@ static const UChar EncISO_8859_9_ToLower https://github.com/ruby/ruby/blob/trunk/enc/iso_8859_9.c#L62 '\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 CaseF https://github.com/ruby/ruby/blob/trunk/enc/iso_8859_9.c#L188 { 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(OnigCaseFoldT https://github.com/ruby/ruby/blob/trunk/enc/iso_8859_9.c#L213 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_ https://github.com/ruby/ruby/blob/trunk/enc/iso_8859_9.c#L287 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") Index: ChangeLog =================================================================== --- ChangeLog (revision 55665) +++ ChangeLog (revision 55666) @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jul 13 18:09:42 2016 Martin Duerst <duerst@i...> + + * 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. + Wed Jul 13 17:21:24 2016 Martin Duerst <duerst@i...> * enc/windows_1252.c, test/ruby/enc/test_case_comprehensive.rb: Index: test/ruby/enc/test_case_comprehensive.rb =================================================================== --- test/ruby/enc/test_case_comprehensive.rb (revision 55665) +++ test/ruby/enc/test_case_comprehensive.rb (revision 55666) @@ -260,7 +260,7 @@ class TestComprehensiveCaseFold https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_case_comprehensive.rb#L260 generate_case_mapping_tests 'ISO-8859-6' generate_case_mapping_tests 'ISO-8859-7' generate_case_mapping_tests 'ISO-8859-8' - generate_ascii_only_case_mapping_tests 'ISO-8859-9' + generate_case_mapping_tests 'ISO-8859-9' generate_case_mapping_tests 'ISO-8859-10' generate_case_mapping_tests 'ISO-8859-11' generate_case_mapping_tests 'ISO-8859-13' Index: test/ruby/enc/test_iso_8859.rb =================================================================== --- test/ruby/enc/test_iso_8859.rb (revision 55665) +++ test/ruby/enc/test_iso_8859.rb (revision 55666) @@ -123,7 +123,7 @@ class TestISO8859 < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_iso_8859.rb#L123 assert_match(/^[\xdfz]+$/i, "sszzsszz") assert_match(/^SS$/i, "\xdf") assert_match(/^Ss$/i, "\xdf") - ([*(0xc0..0xdc)] - [0xd7]).each do |c| + ([*(0xc0..0xde)] - [0xd7, 0xdd]).each do |c| c1 = c.chr("iso8859-9") c2 = (c + 0x20).chr("iso8859-9") assert_match(/^(#{ c1 })\1$/i, c2 + c1) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/