1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2014-11-06 15:00:24 +00:00
parent 4fa166e301
commit d436c05163
3 changed files with 13 additions and 16 deletions

View file

@ -1,3 +1,8 @@
Fri Nov 7 00:00:12 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org> Thu Nov 6 23:58:40 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* pack.c (pack_pack): escape unprintable characters and preserve * pack.c (pack_pack): escape unprintable characters and preserve

View file

@ -84,26 +84,12 @@ module UnicodeNormalize
## Normalization Forms for Patterns (not whole Strings) ## Normalization Forms for Patterns (not whole Strings)
def self.nfd_one(string) def self.nfd_one(string)
string = string.dup string = string.chars.map! {|c| DECOMPOSITION_TABLE[c] || c}.join('')
(0...string.length).each do |position|
if decomposition = DECOMPOSITION_TABLE[string[position]]
string[position] = decomposition
end
end
canonical_ordering_one(hangul_decomp_one(string)) canonical_ordering_one(hangul_decomp_one(string))
end end
def self.nfkd_one(string) def self.nfkd_one(string)
string = string.dup string.chars.map! {|c| KOMPATIBLE_TABLE[c] || c}.join('')
position = 0
while position < string.length
if decomposition = KOMPATIBLE_TABLE[string[position]]
string[position] = decomposition
else
position += 1
end
end
string
end end
def self.nfc_one(string) def self.nfc_one(string)

View file

@ -138,6 +138,12 @@ decomposition_table.each do |key, value|
kompatible_table[key] = value if expanded kompatible_table[key] = value if expanded
end 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 # generate normalization tables file
%># coding: us-ascii %># coding: us-ascii
%# > %# >