Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'refactor-multibyte-chars' of https://github.com/lest/rails

 into multibyte

Conflicts:
	activesupport/lib/active_support/multibyte/chars.rb
  • Loading branch information...
commit f49febe1db52f8127295c4bb4e742b8ab8324e4e 2 parents c4b522d + 7301aa2
@norman norman authored
View
0  activerecord/test/active_record/test_case.rb → activerecord/lib/active_record/test_case.rb
File renamed without changes
View
16 activesupport/lib/active_support/multibyte/chars.rb
@@ -241,14 +241,10 @@ def tidy_bytes(force = false)
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 @@ def translate_offset(byte_offset) #: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
View
2  activesupport/test/multibyte_chars_test.rb
@@ -512,7 +512,7 @@ def test_limit_should_not_break_on_blank_strings
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)
Please sign in to comment.
Something went wrong with that request. Please try again.