method

translate_offset

Importance_0
translate_offset(byte_offset) protected

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activesupport/lib/active_support/multibyte/chars.rb, line 654
        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
Register or log in to add new notes.