diff options
author | Francesco Rodríguez <frodsan@me.com> | 2018-10-20 20:17:05 +0200 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2018-10-20 12:00:37 -0700 |
commit | d684778a000cdcfcac53f6390c565c6a91a3391e (patch) | |
tree | 31f34bbd343cbee008232c62316071ea64de4b2b /activesupport/lib/active_support | |
parent | 5943a5562eeea16afc5b809a1fcdd497ccec9465 (diff) | |
download | rails-d684778a000cdcfcac53f6390c565c6a91a3391e.tar.gz rails-d684778a000cdcfcac53f6390c565c6a91a3391e.tar.bz2 rails-d684778a000cdcfcac53f6390c565c6a91a3391e.zip |
Use String#truncate_bytes inside Multibyte::Chars#limit
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/multibyte/chars.rb | 14 |
1 files changed, 1 insertions, 13 deletions
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 |