From f3abc8ac36055afed9fcc902c33ee146e066d17a Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Mon, 10 May 2010 10:46:37 -0300 Subject: Use multibyte proxy class on 1.9, refactor Unicode. Makes String#mb_chars on Ruby 1.9 return an instance of ActiveSupport::Multibyte::Chars to work around 1.9's lack of Unicode case folding. Refactors class methods from ActiveSupport::Multibyte::Chars into new Unicode module, adding other related functionality for consistency. [#4594 state:resolved] Signed-off-by: Jeremy Kemper --- .../active_support/core_ext/string/multibyte.rb | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/string') diff --git a/activesupport/lib/active_support/core_ext/string/multibyte.rb b/activesupport/lib/active_support/core_ext/string/multibyte.rb index 42e053d0f8..3dfe996d06 100644 --- a/activesupport/lib/active_support/core_ext/string/multibyte.rb +++ b/activesupport/lib/active_support/core_ext/string/multibyte.rb @@ -2,7 +2,7 @@ require 'active_support/multibyte' class String - unless '1.9'.respond_to?(:force_encoding) + if '1.9'.respond_to?(:force_encoding) # == Multibyte proxy # # +mb_chars+ is a multibyte safe proxy for string methods. @@ -37,23 +37,13 @@ class String # For more information about the methods defined on the Chars proxy see ActiveSupport::Multibyte::Chars. For # information about how to change the default Multibyte behaviour see ActiveSupport::Multibyte. def mb_chars - if ActiveSupport::Multibyte.proxy_class.wants?(self) + if ActiveSupport::Multibyte.proxy_class.consumes?(self) ActiveSupport::Multibyte.proxy_class.new(self) else self end end - - # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have - # them), returns false otherwise. - def is_utf8? - ActiveSupport::Multibyte::Chars.consumes?(self) - end - else - def mb_chars #:nodoc - self - end - + def is_utf8? #:nodoc case encoding when Encoding::UTF_8 @@ -64,5 +54,19 @@ class String false end end + else + def mb_chars + if ActiveSupport::Multibyte.proxy_class.wants?(self) + ActiveSupport::Multibyte.proxy_class.new(self) + else + self + end + end + + # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have + # them), returns false otherwise. + def is_utf8? + ActiveSupport::Multibyte::Chars.consumes?(self) + end end end -- cgit v1.2.3