aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/multibyte/chars.rb
diff options
context:
space:
mode:
authorNorman Clarke <norman@njclarke.com>2012-01-05 15:16:03 -0300
committerNorman Clarke <norman@njclarke.com>2012-01-05 15:19:00 -0300
commitf49febe1db52f8127295c4bb4e742b8ab8324e4e (patch)
treea64a3c28287c2c51d4ec435e0e92212e576cfb81 /activesupport/lib/active_support/multibyte/chars.rb
parentc4b522d3c89208b554780e9c49747d07dbe3a4e5 (diff)
parent7301aa2e0d3b16b96fcbffcd79ee9bbf6bc65c57 (diff)
downloadrails-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/lib/active_support/multibyte/chars.rb')
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb16
1 files changed, 5 insertions, 11 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