ruby-changes:43592
From: duerst <ko1@a...>
Date: Wed, 13 Jul 2016 17:21:33 +0900 (JST)
Subject: [ruby-changes:43592] duerst:r55665 (trunk): * enc/windows_1252.c, test/ruby/enc/test_case_comprehensive.rb:
duerst 2016-07-13 17:21:29 +0900 (Wed, 13 Jul 2016) New Revision: 55665 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55665 Log: * enc/windows_1252.c, test/ruby/enc/test_case_comprehensive.rb: Implement non-ASCII case conversion for Windows-1252, by Serina Tai. * test/ruby/enc/test_case_comprehensive.rb: Fix order of encodings. Modified files: trunk/ChangeLog trunk/enc/windows_1252.c trunk/test/ruby/enc/test_case_comprehensive.rb Index: test/ruby/enc/test_case_comprehensive.rb =================================================================== --- test/ruby/enc/test_case_comprehensive.rb (revision 55664) +++ test/ruby/enc/test_case_comprehensive.rb (revision 55665) @@ -279,7 +279,7 @@ class TestComprehensiveCaseFold https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_case_comprehensive.rb#L279 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_ascii_only_case_mapping_tests 'Windows-1252' + generate_case_mapping_tests 'Windows-1252' generate_ascii_only_case_mapping_tests 'Windows-1253' generate_ascii_only_case_mapping_tests 'Windows-1254' generate_case_mapping_tests 'Windows-1255' Index: ChangeLog =================================================================== --- ChangeLog (revision 55664) +++ ChangeLog (revision 55665) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jul 13 17:21:24 2016 Martin Duerst <duerst@i...> + + * enc/windows_1252.c, test/ruby/enc/test_case_comprehensive.rb: + Implement non-ASCII case conversion for Windows-1252, by Serina Tai. + + * test/ruby/enc/test_case_comprehensive.rb: Fix order of encodings. + Wed Jul 13 16:19:14 2016 Martin Duerst <duerst@i...> * enc/iso_8859_7.c, test/ruby/enc/test_case_comprehensive.rb: Index: enc/windows_1252.c =================================================================== --- enc/windows_1252.c (revision 55664) +++ enc/windows_1252.c (revision 55665) @@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/enc/windows_1252.c#L1 /********************************************************************** - windows_1252.c - Oniguruma (regular expression library) + cp1252.c - Oniguruma (regular expression library) **********************************************************************/ /*- * Copyright (c) 2006-2007 Byte <byte AT mail DOT kna DOT ru> @@ -29,6 +29,7 @@ https://github.com/ruby/ruby/blob/trunk/enc/windows_1252.c#L29 */ #include "regenc.h" +#include "iso_8859.h" #define ENC_CP1252_TO_LOWER_CASE(c) EncCP1252_ToLowerCaseTable[c] #define ENC_IS_CP1252_CTYPE(code,ctype) \ @@ -114,7 +115,6 @@ cp1252_mbc_case_fold(OnigCaseFoldType fl https://github.com/ruby/ruby/blob/trunk/enc/windows_1252.c#L115 (*pp)++; return 1; } - static int cp1252_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc ARG_UNUSED) { @@ -180,6 +180,54 @@ cp1252_get_case_fold_codes_by_str(OnigCa https://github.com/ruby/ruby/blob/trunk/enc/windows_1252.c#L180 sizeof(CaseFoldMap)/sizeof(OnigPairCaseFoldCodes), CaseFoldMap, 1, flag, p, end, items); } +#ifdef ONIG_CASE_MAPPING +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 ((EncCP1252_CtypeTable[code] & BIT_CTYPE_UPPER) + && (flags & (ONIGENC_CASE_DOWNCASE|ONIGENC_CASE_FOLD))) { + flags |= ONIGENC_CASE_MODIFIED; + code = ENC_CP1252_TO_LOWER_CASE(code); + } + else if (code==0x83 || code==0xAA || code==0xBA || code==0xB5) ; + else if ((EncCP1252_CtypeTable[code]&BIT_CTYPE_LOWER) + && (flags&ONIGENC_CASE_UPCASE)) { + flags |= ONIGENC_CASE_MODIFIED; + if (code==0x9A || code==0x9C || code==0x9E) + code -= 0x10; + else if (code==0xFF) + code -= 0x60; + 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(windows_1252, Windows_1252) = { onigenc_single_byte_mbc_enc_len, @@ -201,7 +249,7 @@ OnigEncodingDefine(windows_1252, Windows https://github.com/ruby/ruby/blob/trunk/enc/windows_1252.c#L249 0, ONIGENC_FLAG_NONE, #ifdef ONIG_CASE_MAPPING - onigenc_single_byte_ascii_only_case_map, + case_map, #endif /* ONIG_CASE_MAPPING */ }; /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/