提交 f49febe1 编写于 作者: N Norman Clarke

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

Conflicts:
	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
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册