diff --git a/ChangeLog b/ChangeLog index 6fac4b75c6..b5b29671f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Oct 19 17:53:53 2014 Martin Duerst + + * lib/unicode_normalize.rb: Changed to dynamic + loading of actual normalization code and tables. + Sun Oct 19 17:37:37 2014 Martin Duerst * lib/unicode_normalize.rb: Small documentation fix. diff --git a/lib/unicode_normalize.rb b/lib/unicode_normalize.rb index 6a6b5b7bea..576f6806da 100644 --- a/lib/unicode_normalize.rb +++ b/lib/unicode_normalize.rb @@ -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 @@ -61,9 +67,11 @@ class String # "\u00E0".unicode_normalized? #=> true # "\u00E0".unicode_normalized?(:nfd) #=> false # "\xE0".force_encoding('ISO-8859-1').unicode_normalized? - # #=> Encoding::CompatibilityError raised + # #=> 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