private UTF16Offset codeUnitOffsetFor(final CharOffset codePointOffset) {
    int charOffset = 0;
    int codePointsConsumed = 0;

    for (; charOffset < utf16CodeUnits().length() && codePointsConsumed < codePointOffset.asInt();
         ++codePointsConsumed) {
      final int codePoint = utf16CodeUnits().codePointAt(charOffset);
      charOffset += Character.charCount(codePoint);
    }
    if (codePointsConsumed == codePointOffset.asInt()) {
      return UTF16Offset.of(charOffset);
    } else {
      // this will happen if codePointOffset is negative or equal to or greater than the
      // total number of codepoints in the string
      throw new IndexOutOfBoundsException();
    }
  }
private UTF16Offset codeUnitOffsetFor ( final CharOffset codePointOffset ) { int charOffset = 0 ; int codePointsConsumed = 0 ; for ( ; charOffset < utf16CodeUnits ( ) . length ( ) && codePointsConsumed < codePointOffset . asInt ( ) ; ++ codePointsConsumed ) { final int codePoint = utf16CodeUnits ( ) . codePointAt ( charOffset ) ; charOffset += Character . charCount ( codePoint ) ; } if ( codePointsConsumed == codePointOffset . asInt ( ) ) { return UTF16Offset . of ( charOffset ) ; } else { throw new IndexOutOfBoundsException ( ) ; } }
something like LocatedString's like CharacterRegions