private static int alignToCodePointBoundary(CharSequence text, int offset) {
    return offset > 0 && offset < text.length() &&
           Character.isHighSurrogate(text.charAt(offset - 1)) && Character.isLowSurrogate(text.charAt(offset)) ? offset - 1 : offset;
  }
private static int alignToCodePointBoundary(CharSequence text, int offset)