From d684778a000cdcfcac53f6390c565c6a91a3391e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Rodr=C3=ADguez?= Date: Sat, 20 Oct 2018 20:17:05 +0200 Subject: Use String#truncate_bytes inside Multibyte::Chars#limit --- activesupport/lib/active_support/multibyte/chars.rb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index bd8cab3460..a1e23aeaca 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -122,7 +122,7 @@ module ActiveSupport #:nodoc: # # 'こんにちは'.mb_chars.limit(7).to_s # => "こん" def limit(limit) - slice(0...translate_offset(limit)) + truncate_bytes(limit, omission: nil) end # Capitalizes the first letter of every word, when possible. @@ -208,18 +208,6 @@ module ActiveSupport #:nodoc: private - def translate_offset(byte_offset) - return nil if byte_offset.nil? - return 0 if @wrapped_string == "" - - begin - @wrapped_string.byteslice(0...byte_offset).unpack("U*").length - rescue ArgumentError - byte_offset -= 1 - retry - end - end - def chars(string) self.class.new(string) end -- cgit v1.2.3