mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
rework definition of String#unicode_normalize! and #unicode_normalized?
simplify String#unicode_normalize! and #unicode_normalized? in lib/unicode_normalize.rb by redefining them in lib/unicode_normalize/normalize.rb git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
42b8713703
commit
8001dae820
2 changed files with 10 additions and 5 deletions
|
@ -42,8 +42,7 @@ class String
|
||||||
#
|
#
|
||||||
def unicode_normalize!(form = :nfc)
|
def unicode_normalize!(form = :nfc)
|
||||||
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
|
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
|
||||||
# String.send(:define_method, :unicode_normalize!, ->(form = :nfc) { replace(unicode_normalize(form)) } )
|
unicode_normalize! form
|
||||||
replace(unicode_normalize(form))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# :call-seq:
|
# :call-seq:
|
||||||
|
@ -65,8 +64,7 @@ class String
|
||||||
#
|
#
|
||||||
def unicode_normalized?(form = :nfc)
|
def unicode_normalized?(form = :nfc)
|
||||||
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
|
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
|
||||||
# String.send(:define_method, :unicode_normalized?, ->(form = :nfc) { UnicodeNormalize.normalized?(self, form) } )
|
unicode_normalized? form
|
||||||
UnicodeNormalize.normalized?(self, form)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -157,11 +157,18 @@ module UnicodeNormalize # :nodoc:
|
||||||
raise Encoding::CompatibilityError, "Unicode Normalization not appropriate for #{encoding}"
|
raise Encoding::CompatibilityError, "Unicode Normalization not appropriate for #{encoding}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end # module
|
end # module
|
||||||
|
|
||||||
class String # :nodoc:
|
class String # :nodoc:
|
||||||
def unicode_normalize(form = :nfc)
|
def unicode_normalize(form = :nfc)
|
||||||
UnicodeNormalize.normalize(self, form)
|
UnicodeNormalize.normalize(self, form)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unicode_normalize!(form = :nfc)
|
||||||
|
replace(UnicodeNormalize.normalize(self, form))
|
||||||
|
end
|
||||||
|
|
||||||
|
def unicode_normalized?(form = :nfc)
|
||||||
|
UnicodeNormalize.normalized?(self, form)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue