CodePointsOffsets (@NotNull CharSequence text) { IntList codePoints = new IntArrayList(text.length()); IntList offsets = new IntArrayList(text.length()); int len = text.length(); int offset = 0; while (offset < len) { int ch = Character.codePointAt(text, offset); int charCount = Character.charCount(ch); if (!isWhiteSpaceCodePoint(ch)) { codePoints.add(ch); offsets.add(offset); } offset += charCount; } return new CodePointsOffsets(codePoints.toIntArray(), offsets.toIntArray()); }