class Reline::Unicode

def self.em_backward_word(line, byte_pointer)

def self.em_backward_word(line, byte_pointer)
  width = 0
  byte_size = 0
  while 0 < (byte_pointer - byte_size)
    size = get_prev_mbchar_size(line, byte_pointer - byte_size)
    mbchar = line.byteslice(byte_pointer - byte_size - size, size)
    break if mbchar.encode(Encoding::UTF_8) =~ /\p{Word}/
    width += get_mbchar_width(mbchar)
    byte_size += size
  end
  while 0 < (byte_pointer - byte_size)
    size = get_prev_mbchar_size(line, byte_pointer - byte_size)
    mbchar = line.byteslice(byte_pointer - byte_size - size, size)
    break if mbchar.encode(Encoding::UTF_8) =~ /\P{Word}/
    width += get_mbchar_width(mbchar)
    byte_size += size
  end
  [byte_size, width]
end