mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
lib/unicode_normalize.rb: Changed to dynamic loading of actual normalization code and tables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8a252f6b70
commit
d72053c0a3
2 changed files with 16 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Oct 19 17:53:53 2014 Martin Duerst <duerst@it.aoyama.ac.jp>
|
||||
|
||||
* lib/unicode_normalize.rb: Changed to dynamic
|
||||
loading of actual normalization code and tables.
|
||||
|
||||
Sun Oct 19 17:37:37 2014 Martin Duerst <duerst@it.aoyama.ac.jp>
|
||||
|
||||
* lib/unicode_normalize.rb: Small documentation fix.
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
# Copyright Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
|
||||
|
||||
require 'unicode_normalize/normalize.rb'
|
||||
|
||||
# additions to class String for Unicode normalization
|
||||
class String
|
||||
# === Unicode Normalization
|
||||
|
@ -31,6 +29,12 @@ class String
|
|||
# #=> Encoding::CompatibilityError raised
|
||||
#
|
||||
def unicode_normalize(form = :nfc)
|
||||
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
|
||||
## The following line can be uncommented to avoid repeated checking for
|
||||
## UnicodeNormalize. However, tests didn't show any noticeable speedup
|
||||
## when doing this. This comment also applies to the commented out lines
|
||||
## in String#unicode_normalize! and String#unicode_normalized?.
|
||||
# String.send(:define_method, :normalize, ->(form = :nfc) { UnicodeNormalize.normalize(self, form) } )
|
||||
UnicodeNormalize.normalize(self, form)
|
||||
end
|
||||
|
||||
|
@ -41,6 +45,8 @@ class String
|
|||
# normalization in place.
|
||||
#
|
||||
def unicode_normalize!(form = :nfc)
|
||||
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
|
||||
# String.send(:define_method, :normalize!, ->(form = :nfc) { replace(normalize(form)) } )
|
||||
replace(self.normalize(form))
|
||||
end
|
||||
|
||||
|
@ -64,6 +70,8 @@ class String
|
|||
# #=> Encoding::CompatibilityError raised
|
||||
#
|
||||
def unicode_normalized?(form = :nfc)
|
||||
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
|
||||
# String.send(:define_method, :unicode_normalized?, ->(form = :nfc) { UnicodeNormalize.normalized?(self, form) } )
|
||||
UnicodeNormalize.normalized?(self, form)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue