summaryrefslogtreecommitdiff
path: root/lib/unicode_normalize
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-06 15:00:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-06 15:00:17 +0000
commitb8788417f0fcf25a7982d1e52ef73f8b277d97f4 (patch)
treeb700d0570bf5f42d6c1376d3cc74238fa1bfd951 /lib/unicode_normalize
parent64034372b7a4faac73628f5ec1060eaf8d550919 (diff)
normalize.rb: trivial optimizations
* lib/unicode_normalize/normalize.rb (nfc_one, normalize): trivial optimizations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/unicode_normalize')
-rw-r--r--lib/unicode_normalize/normalize.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/unicode_normalize/normalize.rb b/lib/unicode_normalize/normalize.rb
index 1e8fcd8..bc8831c 100644
--- a/lib/unicode_normalize/normalize.rb
+++ b/lib/unicode_normalize/normalize.rb
@@ -106,7 +106,7 @@ module UnicodeNormalize
string
end
- def self.nfc_one (string)
+ def self.nfc_one(string)
nfd_string = nfd_one string
start = nfd_string[0]
last_class = CLASS_TABLE[start]-1
@@ -116,7 +116,7 @@ module UnicodeNormalize
if last_class<accent_class and composite = COMPOSITION_TABLE[start+accent]
start = composite
else
- accents += accent
+ accents << accent
last_class = accent_class
end
end
@@ -125,7 +125,8 @@ module UnicodeNormalize
def self.normalize(string, form = :nfc)
encoding = string.encoding
- if encoding == Encoding::UTF_8
+ case encoding
+ when Encoding::UTF_8
case form
when :nfc then
string.gsub REGEXP_C, NF_HASH_C
@@ -138,9 +139,9 @@ module UnicodeNormalize
else
raise ArgumentError, "Invalid normalization form #{form}."
end
- elsif encoding == Encoding::US_ASCII
+ when Encoding::US_ASCII
string
- elsif UNICODE_ENCODINGS.include? encoding
+ when *UNICODE_ENCODINGS
normalize(string.encode(Encoding::UTF_8), form).encode(encoding)
else
raise Encoding::CompatibilityError, "Unicode Normalization not appropriate for #{encoding}"