ruby-changes:43222
From: duerst <ko1@a...>
Date: Mon, 6 Jun 2016 18:36:43 +0900 (JST)
Subject: [ruby-changes:43222] duerst:r55296 (trunk): * string.c: Added UTF-16BE/LE and UTF-32BE/LE to supported encodings
duerst 2016-06-06 18:36:36 +0900 (Mon, 06 Jun 2016) New Revision: 55296 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55296 Log: * string.c: Added UTF-16BE/LE and UTF-32BE/LE to supported encodings for Unicode case mapping. * test/ruby/enc/test_case_comprehensive.rb: Tests for above functionality; fixed an encoding issue in assertion error message. Modified files: trunk/ChangeLog trunk/string.c trunk/test/ruby/enc/test_case_comprehensive.rb Index: string.c =================================================================== --- string.c (revision 55295) +++ string.c (revision 55296) @@ -5858,7 +5858,7 @@ rb_str_upcase_bang(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/string.c#L5858 enc = STR_ENC_GET(str); rb_str_check_dummy_enc(enc); s = RSTRING_PTR(str); send = RSTRING_END(str); - if (enc==rb_utf8_encoding()) { + if (rb_enc_unicode_p(enc)) { str_shared_replace(str, rb_str_casemap(str, &flags, enc)); modify = ONIGENC_CASE_MODIFIED & flags; } @@ -5948,7 +5948,7 @@ rb_str_downcase_bang(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/string.c#L5948 enc = STR_ENC_GET(str); rb_str_check_dummy_enc(enc); s = RSTRING_PTR(str); send = RSTRING_END(str); - if (enc==rb_utf8_encoding()) { + if (rb_enc_unicode_p(enc)) { str_shared_replace(str, rb_str_casemap(str, &flags, enc)); modify = ONIGENC_CASE_MODIFIED & flags; } @@ -6037,8 +6037,9 @@ rb_str_downcase_bang(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/string.c#L6037 * normalization (i.e. String#unicode_normalize) is not necessarily maintained * by case mapping operations. * - * Non-ASCII case mapping/folding is currently only supported for UTF-8 - * Strings/Symbols, but this support will be extended to other encodings. + * Non-ASCII case mapping/folding is currently supported for UTF-8, + * UTF-16BE/LE, and UTF-32BE/LE Strings/Symbols. + * This support will be extended to other encodings. * * "hEllO".downcase #=> "hello" */ @@ -6083,7 +6084,7 @@ rb_str_capitalize_bang(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/string.c#L6084 enc = STR_ENC_GET(str); rb_str_check_dummy_enc(enc); if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return Qnil; - if (enc==rb_utf8_encoding()) { + if (rb_enc_unicode_p(enc)) { str_shared_replace(str, rb_str_casemap(str, &flags, enc)); modify = ONIGENC_CASE_MODIFIED & flags; } @@ -6159,7 +6160,7 @@ rb_str_swapcase_bang(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/string.c#L6160 enc = STR_ENC_GET(str); rb_str_check_dummy_enc(enc); s = RSTRING_PTR(str); send = RSTRING_END(str); - if (enc==rb_utf8_encoding()) { + if (rb_enc_unicode_p(enc)) { str_shared_replace(str, rb_str_casemap(str, &flags, enc)); modify = ONIGENC_CASE_MODIFIED & flags; } Index: test/ruby/enc/test_case_comprehensive.rb =================================================================== --- test/ruby/enc/test_case_comprehensive.rb (revision 55295) +++ test/ruby/enc/test_case_comprehensive.rb (revision 55296) @@ -119,7 +119,7 @@ class TestComprehensiveCaseFold < Test:: https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_case_comprehensive.rb#L119 target = test.first_data[code].encode(encoding) + test.follow_data[code].encode(encoding) * 4 result = source.send(test.method_name, *test.attributes) assert_equal target, result, - "from #{source} (#{source.dump}) expected #{target.dump} but was #{result.dump}" + "from #{code*5} (#{source.dump}) expected #{target.dump} but was #{result.dump}" rescue Encoding::UndefinedConversionError end end @@ -139,4 +139,8 @@ class TestComprehensiveCaseFold < Test:: https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_case_comprehensive.rb#L139 generate_casefold_tests 'US-ASCII' generate_casefold_tests 'ASCII-8BIT' generate_casefold_tests 'UTF-8' + generate_casefold_tests 'UTF-16BE' + generate_casefold_tests 'UTF-16LE' + generate_casefold_tests 'UTF-32BE' + generate_casefold_tests 'UTF-32LE' end Index: ChangeLog =================================================================== --- ChangeLog (revision 55295) +++ ChangeLog (revision 55296) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jun 6 18:36:34 2016 Martin Duerst <duerst@i...> + + * string.c: Added UTF-16BE/LE and UTF-32BE/LE to supported encodings + for Unicode case mapping. + + * test/ruby/enc/test_case_comprehensive.rb: Tests for above + functionality; fixed an encoding issue in assertion error message. + Mon Jun 6 17:29:35 2016 Martin Duerst <duerst@i...> * test/ruby/enc/test_case_comprehensive.rb: Speed up testing for small -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/