# File lib/rbreadline.rb, line 3835
  def _rl_col_width(string,start,_end)
    return 0 if _end <= start

    # Find the first occurance of 0.chr, which marks the end of the string.
    # Because newlines are also in the string as 0.chrs (they are tracked
    # seperately), we need to ignore any 0.chrs that lie before _end.
    index = string[_end...string.length].index(0.chr)

    str = index ? string[0,index+_end] : string
    width = 0

    case @encoding
    when 'N'
      return (_end - start)
    when 'U'
      str[start ... _end].scan(/./mu).each {|s| width += s.unpack('U').first >= 0x1000 ? 2 : 1 }
    when 'S'
      str[start ... _end].scan(/./ms).each {|s| width += s.length }
    when 'E'
      str[start ... _end].scan(/./me).each {|s| width += s.length }
    when 'X'
      str[start ... _end].force_encoding(@encoding_name).codepoints.each {|s| width += s > 0x1000 ? 2 : 1 }
    end
    width
  end