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

ruby-changes:36230

From: nobu <ko1@a...>
Date: Fri, 7 Nov 2014 00:00:41 +0900 (JST)
Subject: [ruby-changes:36230] nobu:r48311 (trunk): unicode_norm_gen.tmpl: expand kompatible_table

nobu	2014-11-07 00:00:24 +0900 (Fri, 07 Nov 2014)

  New Revision: 48311

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

  Log:
    unicode_norm_gen.tmpl: expand kompatible_table
    
    * template/unicode_norm_gen.tmpl: expand kompatible_table so that
      recursive expansion is not needed at runtime.

  Modified files:
    trunk/ChangeLog
    trunk/lib/unicode_normalize/normalize.rb
    trunk/template/unicode_norm_gen.tmpl
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48310)
+++ ChangeLog	(revision 48311)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Nov  7 00:00:12 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* template/unicode_norm_gen.tmpl: expand kompatible_table so that
+	  recursive expansion is not needed at runtime.
+
 Thu Nov  6 23:58:40 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* pack.c (pack_pack): escape unprintable characters and preserve
Index: lib/unicode_normalize/normalize.rb
===================================================================
--- lib/unicode_normalize/normalize.rb	(revision 48310)
+++ lib/unicode_normalize/normalize.rb	(revision 48311)
@@ -84,26 +84,12 @@ module UnicodeNormalize https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L84
 
   ## Normalization Forms for Patterns (not whole Strings)
   def self.nfd_one(string)
-    string = string.dup
-    (0...string.length).each do |position|
-      if decomposition = DECOMPOSITION_TABLE[string[position]]
-        string[position] = decomposition
-      end
-    end
+    string = string.chars.map! {|c| DECOMPOSITION_TABLE[c] || c}.join('')
     canonical_ordering_one(hangul_decomp_one(string))
   end
 
   def self.nfkd_one(string)
-    string = string.dup
-    position = 0
-    while position < string.length
-      if decomposition = KOMPATIBLE_TABLE[string[position]]
-        string[position] = decomposition
-      else
-        position += 1
-      end
-    end
-    string
+    string.chars.map! {|c| KOMPATIBLE_TABLE[c] || c}.join('')
   end
 
   def self.nfc_one(string)
Index: template/unicode_norm_gen.tmpl
===================================================================
--- template/unicode_norm_gen.tmpl	(revision 48310)
+++ template/unicode_norm_gen.tmpl	(revision 48311)
@@ -138,6 +138,12 @@ decomposition_table.each do |key, value| https://github.com/ruby/ruby/blob/trunk/template/unicode_norm_gen.tmpl#L138
   kompatible_table[key] = value if expanded
 end
 
+while kompatible_table.any? {|key, value|
+        expanded = value.map {|v| kompatible_table[v] || v}.flatten
+        kompatible_table[key] = expanded unless value == expanded
+      }
+end
+
 # generate normalization tables file
 %># coding: us-ascii
 %# >

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

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