Skip to content

Instantly share code, notes, and snippets.

@bhamiltoncx
Created March 30, 2017 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhamiltoncx/9282e943efab384220723a0daa37d72e to your computer and use it in GitHub Desktop.
Save bhamiltoncx/9282e943efab384220723a0daa37d72e to your computer and use it in GitHub Desktop.
public final class CodePointCounter {
private final String input;
public int inputIndex = 0;
public int codePointIndex = 0;
public int advanceToIndex(int newCodePointIndex) {
assert newCodePointIndex >= codePointIndex;
while (codePointIndex < newCodePointOffset) {
int codePoint = Character.codePointAt(input, inputIndex);
inputIndex += Character.charCount(codePoint);
codePointIndex++;
}
return inputIndex;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment