class Reline::Unicode

def self.vi_forward_word(line, byte_pointer, drop_terminate_spaces = false)

def self.vi_forward_word(line, byte_pointer, drop_terminate_spaces = false)
  if line.bytesize > byte_pointer
    size = get_next_mbchar_size(line, byte_pointer)
    mbchar = line.byteslice(byte_pointer, size)
    if mbchar =~ /\w/
      started_by = :word
    elsif mbchar =~ /\s/
      started_by = :space
    else
      started_by = :non_word_printable
    end
    width = get_mbchar_width(mbchar)
    byte_size = size
  else
    return [0, 0]
  end
  while line.bytesize > (byte_pointer + byte_size)
    size = get_next_mbchar_size(line, byte_pointer + byte_size)
    mbchar = line.byteslice(byte_pointer + byte_size, size)
    case started_by
    when :word
      break if mbchar =~ /\W/
    when :space
      break if mbchar =~ /\S/
    when :non_word_printable
      break if mbchar =~ /\w|\s/
    end
    width += get_mbchar_width(mbchar)
    byte_size += size
  end
  return [byte_size, width] if drop_terminate_spaces
  while line.bytesize > (byte_pointer + byte_size)
    size = get_next_mbchar_size(line, byte_pointer + byte_size)
    mbchar = line.byteslice(byte_pointer + byte_size, size)
    break if mbchar =~ /\S/
    width += get_mbchar_width(mbchar)
    byte_size += size
  end
  [byte_size, width]
end