mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
97e21517a3
commit
84b5bb9802
1 changed files with 2 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue