[前][次][番号順一覧][スレッド一覧]

ruby-changes:43299

From: duerst <ko1@a...>
Date: Sat, 11 Jun 2016 09:46:26 +0900 (JST)
Subject: [ruby-changes:43299] duerst:r55373 (trunk): * enc/iso_8859_1.c: Implement non-ASCII case mapping.

duerst	2016-06-11 09:46:21 +0900 (Sat, 11 Jun 2016)

  New Revision: 55373

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55373

  Log:
    * enc/iso_8859_1.c: Implement non-ASCII case mapping.
    * test/ruby/enc/test_case_comprehensive.rb: Tests for above.
    * string.c: Add iso-8859-1 to supported encodings.

  Modified files:
    trunk/ChangeLog
    trunk/enc/iso_8859_1.c
    trunk/string.c
    trunk/test/ruby/enc/test_case_comprehensive.rb
Index: enc/iso_8859_1.c
===================================================================
--- enc/iso_8859_1.c	(revision 55372)
+++ enc/iso_8859_1.c	(revision 55373)
@@ -254,6 +254,49 @@ is_code_ctype(OnigCodePoint code, unsign https://github.com/ruby/ruby/blob/trunk/enc/iso_8859_1.c#L254
     return FALSE;
 }
 
+#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, lower;
+  OnigUChar *to_start = to;
+  OnigCaseFoldType flags = *flagP;
+
+  while (*pp<end && to<to_end) {
+    code = *(*pp)++;
+    if (code==0xdf) {  /* 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 ((lower=ONIGENC_ISO_8859_1_TO_LOWER_CASE(code)) != code)
+	     && (flags&ONIGENC_CASE_UPCASE)) {
+	flags |= ONIGENC_CASE_MODIFIED;
+	code = lower;
+    }
+    else if ((EncISO_8859_1_CtypeTable[code]&BIT_CTYPE_LOWER)
+	     && (flags&ONIGENC_CASE_UPCASE)) {
+	flags |= ONIGENC_CASE_MODIFIED;
+	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_1, ISO_8859_1) = {
   onigenc_single_byte_mbc_enc_len,
   "ISO-8859-1",  /* name */
@@ -274,7 +317,7 @@ OnigEncodingDefine(iso_8859_1, ISO_8859_ https://github.com/ruby/ruby/blob/trunk/enc/iso_8859_1.c#L317
   0,
   ONIGENC_FLAG_NONE,
 #ifdef ONIG_CASE_MAPPING
-  onigenc_single_byte_ascii_only_case_map,
+  case_map,
 #endif   /* ONIG_CASE_MAPPING */
 };
 ENC_ALIAS("ISO8859-1", "ISO-8859-1")
Index: string.c
===================================================================
--- string.c	(revision 55372)
+++ string.c	(revision 55373)
@@ -6011,7 +6011,7 @@ rb_str_downcase_bang(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/string.c#L6011
  *  by case mapping operations.
  *
  *  Non-ASCII case mapping/folding is currently supported for UTF-8,
- *  UTF-16BE/LE, and UTF-32BE/LE Strings/Symbols.
+ *  UTF-16BE/LE, UTF-32BE/LE, and ISO-8859-1 Strings/Symbols.
  *  This support will be extended to other encodings.
  *
  *     "hEllO".downcase   #=> "hello"
Index: test/ruby/enc/test_case_comprehensive.rb
===================================================================
--- test/ruby/enc/test_case_comprehensive.rb	(revision 55372)
+++ test/ruby/enc/test_case_comprehensive.rb	(revision 55373)
@@ -186,7 +186,6 @@ class TestComprehensiveCaseFold < Test:: https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_case_comprehensive.rb#L186
     %w[UnicodeData CaseFolding SpecialCasing].each { |f| check_file_available f }
   end
 
-  generate_ascii_only_case_mapping_tests 'ISO-8859-1'
   generate_ascii_only_case_mapping_tests 'ISO-8859-2'
   generate_ascii_only_case_mapping_tests 'ISO-8859-3'
   generate_ascii_only_case_mapping_tests 'ISO-8859-4'
@@ -215,6 +214,7 @@ class TestComprehensiveCaseFold < Test:: https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_case_comprehensive.rb#L214
   generate_ascii_only_case_mapping_tests 'Windows-1254'
   generate_ascii_only_case_mapping_tests 'Windows-1256'
   generate_ascii_only_case_mapping_tests 'Windows-1257'
+  generate_case_mapping_tests 'ISO-8859-1'
   generate_case_mapping_tests 'US-ASCII'
   generate_case_mapping_tests 'ASCII-8BIT'
   generate_case_mapping_tests 'UTF-8'
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55372)
+++ ChangeLog	(revision 55373)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun 11 09:46:17 2016  Martin Duerst  <duerst@i...>
+
+	* enc/iso_8859_1.c: Implement non-ASCII case mapping.
+
+	* test/ruby/enc/test_case_comprehensive.rb: Tests for above.
+
+	* string.c: Add iso-8859-1 to supported encodings.
+
 Sat Jun 11 09:31:28 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/forwardable.rb (_delegator_method): leave the backtrace

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]