method
translate_offset
translate_offset(byte_offset)
protected
Hide source
# File activesupport/lib/active_support/multibyte/chars.rb, line 626 def translate_offset(byte_offset) #:nodoc: return nil if byte_offset.nil? return 0 if @wrapped_string == '' chunk = @wrapped_string[0..byte_offset] begin begin chunk.unpack('U*').length - 1 rescue ArgumentError => e chunk = @wrapped_string[0..(byte_offset+=1)] # Stop retrying at the end of the string raise e unless byte_offset < chunk.length # We damaged a character, retry retry end # Catch the ArgumentError so we can throw our own rescue ArgumentError raise EncodingError, 'malformed UTF-8 character' end end