From 84b5bb9802d8079d92c8e4c432f0b37e9589bc99 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 11 Mar 2015 03:56:44 +0000 Subject: 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 --- lib/unicode_normalize/normalize.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'lib/unicode_normalize') 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 -- cgit v1.2.3