diff options
author | Norman Clarke <norman@njclarke.com> | 2012-01-05 15:16:03 -0300 |
---|---|---|
committer | Norman Clarke <norman@njclarke.com> | 2012-01-05 15:19:00 -0300 |
commit | f49febe1db52f8127295c4bb4e742b8ab8324e4e (patch) | |
tree | a64a3c28287c2c51d4ec435e0e92212e576cfb81 /activesupport | |
parent | c4b522d3c89208b554780e9c49747d07dbe3a4e5 (diff) | |
parent | 7301aa2e0d3b16b96fcbffcd79ee9bbf6bc65c57 (diff) | |
download | rails-f49febe1db52f8127295c4bb4e742b8ab8324e4e.tar.gz rails-f49febe1db52f8127295c4bb4e742b8ab8324e4e.tar.bz2 rails-f49febe1db52f8127295c4bb4e742b8ab8324e4e.zip |
Merge branch 'refactor-multibyte-chars' of https://github.com/lest/rails into multibyte
Conflicts:
activesupport/lib/active_support/multibyte/chars.rb
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/multibyte/chars.rb | 16 | ||||
-rw-r--r-- | activesupport/test/multibyte_chars_test.rb | 2 |
2 files changed, 6 insertions, 12 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index 027aadb029..fbc469ae12 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -241,14 +241,10 @@ module ActiveSupport #:nodoc: chars(Unicode.tidy_bytes(@wrapped_string, force)) end - %w(capitalize downcase lstrip reverse rstrip strip tidy_bytes upcase).each do |method| - # Only define a corresponding bang method for methods defined in the proxy; On 1.9 the proxy will - # exclude lstrip!, rstrip! and strip! because they are already work as expected on multibyte strings. - if public_method_defined?(method) - define_method("#{method}!") do |*args| - @wrapped_string = send(args.nil? ? method : method, *args).to_s - self - end + %w(capitalize downcase reverse tidy_bytes upcase).each do |method| + define_method("#{method}!") do |*args| + @wrapped_string = send(method, *args).to_s + self end end @@ -258,10 +254,8 @@ module ActiveSupport #:nodoc: return nil if byte_offset.nil? return 0 if @wrapped_string == '' - @wrapped_string = @wrapped_string.dup.force_encoding(Encoding::ASCII_8BIT) - begin - @wrapped_string[0...byte_offset].unpack('U*').length + @wrapped_string.byteslice(0...byte_offset).unpack('U*').length rescue ArgumentError byte_offset -= 1 retry diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index 41248cccb6..f25e062873 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -512,7 +512,7 @@ class MultibyteCharsExtrasTest < Test::Unit::TestCase def test_limit_should_work_on_a_multibyte_string example = chars(UNICODE_STRING) - bytesize = UNICODE_STRING.respond_to?(:bytesize) ? UNICODE_STRING.bytesize : UNICODE_STRING.size + bytesize = UNICODE_STRING.bytesize assert_equal UNICODE_STRING, example.limit(bytesize) assert_equal '', example.limit(0) |