From 62b511b6aa9e2c1ceb11048f012eed13e5feabfb Mon Sep 17 00:00:00 2001 From: duerst Date: Sun, 9 Nov 2014 09:33:36 +0000 Subject: [PATCH] lib/unicode_normalize/normalize.rb: Replaced if-else by case in self.normalized? in parallel to r48309. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/unicode_normalize/normalize.rb | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d06cc619c9..f725a5c9fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Nov 9 18:33:33 2014 Martin Duerst + + * lib/unicode_normalize/normalize.rb: Replaced if-else by + case in self.normalized? in parallel to r48309. + Sun Nov 9 18:07:00 2014 Tanaka Akira * test/xmlrpc: Use assert_join_threads. diff --git a/lib/unicode_normalize/normalize.rb b/lib/unicode_normalize/normalize.rb index 5fea8c5548..86e83f2afe 100644 --- a/lib/unicode_normalize/normalize.rb +++ b/lib/unicode_normalize/normalize.rb @@ -136,7 +136,8 @@ module UnicodeNormalize def self.normalized?(string, form = :nfc) encoding = string.encoding - if encoding == Encoding::UTF_8 + case encoding + when Encoding::UTF_8 case form when :nfc then string.scan REGEXP_C do |match| @@ -155,9 +156,9 @@ module UnicodeNormalize else raise ArgumentError, "Invalid normalization form #{form}." end - elsif encoding == Encoding::US_ASCII + when Encoding::US_ASCII true - elsif UNICODE_ENCODINGS.include? encoding + when **UNICODE_ENCODINGS normalized? string.encode(Encoding::UTF_8), form else raise Encoding::CompatibilityError, "Unicode Normalization not appropriate for #{encoding}"