diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-03-11 03:56:44 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-03-11 03:56:44 +0000 |
commit | 84b5bb9802d8079d92c8e4c432f0b37e9589bc99 (patch) | |
tree | 3c8723d0037ff7ca68a7aaef0232759cb5a2041d /lib | |
parent | 97e21517a3c79b9b144b7160afd545c283815413 (diff) | |
download | ruby-84b5bb9802d8079d92c8e4c432f0b37e9589bc99.tar.gz |
normalize.rb: remove redundant hash
* lib/unicode_normalize/normalize.rb (UnicodeNormalize): REGEXP_K
matches only single chars which are keys of KOMPATIBLE_TABLE, so
string in nfkd_one is always single char and one of the key of
KOMPATIBLE_TABLE, that is that the default proc of NF_HASH_K only
copies a pair in KOMPATIBLE_TABLE. therefore NF_HASH_K is a
part of KOMPATIBLE_TABLE always, and just redundant.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicode_normalize/normalize.rb | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/lib/unicode_normalize/normalize.rb b/lib/unicode_normalize/normalize.rb index 1511f75f8a..18080ce03d 100644 --- a/lib/unicode_normalize/normalize.rb +++ b/lib/unicode_normalize/normalize.rb @@ -21,10 +21,6 @@ module UnicodeNormalize hash.shift if hash.length>MAX_HASH_LENGTH # prevent DoS attack hash[key] = nfc_one(key) end - NF_HASH_K = Hash.new do |hash, key| - hash.shift if hash.length>MAX_HASH_LENGTH # prevent DoS attack - hash[key] = nfkd_one(key) - end ## Constants For Hangul # for details such as the meaning of the identifiers below, please see @@ -88,10 +84,6 @@ module UnicodeNormalize canonical_ordering_one(hangul_decomp_one(string)) end - def self.nfkd_one(string) - string.chars.map! {|c| KOMPATIBLE_TABLE[c] || c}.join('') - end - def self.nfc_one(string) nfd_string = nfd_one string start = nfd_string[0] @@ -119,9 +111,9 @@ module UnicodeNormalize when :nfd then string.gsub REGEXP_D, NF_HASH_D when :nfkc then - string.gsub(REGEXP_K, NF_HASH_K).gsub REGEXP_C, NF_HASH_C + string.gsub(REGEXP_K, KOMPATIBLE_TABLE).gsub(REGEXP_C, NF_HASH_C) when :nfkd then - string.gsub(REGEXP_K, NF_HASH_K).gsub REGEXP_D, NF_HASH_D + string.gsub(REGEXP_K, KOMPATIBLE_TABLE).gsub(REGEXP_D, NF_HASH_D) else raise ArgumentError, "Invalid normalization form #{form}." end |