def _get_char_to_byte_map(self, text):
    """Returns a map from character to byte offsets.

    Args:
      text (str): a Unicode string.

    Returns:
      a map from each character offset to a byte offset.
    """
    char_to_byte_map = {}
    char_offset = 0
    byte_offset = 0
    for character in text:
      char_to_byte_map[char_offset] = byte_offset
      char_offset += 1
      byte_offset += len(character.encode('utf-8'))
    # Corresponds to the position right after the last character.
    char_to_byte_map[char_offset] = byte_offset
    return char_to_byte_map
Returns a map from character to byte offsets.

    Args:
      text (str): a Unicode string.

    Returns:
      a map from each character offset to a byte offset.
    
language/realm/featurization.py