From d436c051630a4406971645c7b44d84f4f00a0ff8 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 6 Nov 2014 15:00:24 +0000 Subject: [PATCH] unicode_norm_gen.tmpl: expand kompatible_table * template/unicode_norm_gen.tmpl: expand kompatible_table so that recursive expansion is not needed at runtime. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/unicode_normalize/normalize.rb | 18 ++---------------- template/unicode_norm_gen.tmpl | 6 ++++++ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index df021606a7..8d946cc9a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Nov 7 00:00:12 2014 Nobuyoshi Nakada + + * 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 * pack.c (pack_pack): escape unprintable characters and preserve diff --git a/lib/unicode_normalize/normalize.rb b/lib/unicode_normalize/normalize.rb index bc8831c6b7..5fea8c5548 100644 --- a/lib/unicode_normalize/normalize.rb +++ b/lib/unicode_normalize/normalize.rb @@ -84,26 +84,12 @@ module UnicodeNormalize ## 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) diff --git a/template/unicode_norm_gen.tmpl b/template/unicode_norm_gen.tmpl index 82498d0b41..2123643018 100644 --- a/template/unicode_norm_gen.tmpl +++ b/template/unicode_norm_gen.tmpl @@ -138,6 +138,12 @@ decomposition_table.each do |key, value| 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 %# >