Methods Summary |
---|
private void | checkOffsetIsValid(int shiftedOffset)
if (shiftedOffset < 0 || shiftedOffset > mString.length()) {
throw new IllegalArgumentException("Invalid offset: " + (shiftedOffset + mOffsetShift) +
". Valid range is [" + mOffsetShift + ", " + (mString.length() + mOffsetShift) +
"]");
}
|
public int | following(int offset){@inheritDoc}
int shiftedOffset = offset - mOffsetShift;
do {
shiftedOffset = mIterator.following(shiftedOffset);
if (shiftedOffset == BreakIterator.DONE) {
return BreakIterator.DONE;
}
if (isAfterLetterOrDigit(shiftedOffset)) {
return shiftedOffset + mOffsetShift;
}
} while (true);
|
public int | getBeginning(int offset)If offset is within a word, returns the index of the first character of that
word, otherwise returns BreakIterator.DONE.
The offsets that are considered to be part of a word are the indexes of its characters,
as well as the index of its last character plus one.
If offset is the index of a low surrogate character, BreakIterator.DONE will be returned.
Valid range for offset is [0..textLength] (note the inclusive upper bound).
The returned value is within [0..offset] or BreakIterator.DONE.
final int shiftedOffset = offset - mOffsetShift;
checkOffsetIsValid(shiftedOffset);
if (isOnLetterOrDigit(shiftedOffset)) {
if (mIterator.isBoundary(shiftedOffset)) {
return shiftedOffset + mOffsetShift;
} else {
return mIterator.preceding(shiftedOffset) + mOffsetShift;
}
} else {
if (isAfterLetterOrDigit(shiftedOffset)) {
return mIterator.preceding(shiftedOffset) + mOffsetShift;
}
}
return BreakIterator.DONE;
|
public int | getEnd(int offset)If offset is within a word, returns the index of the last character of that
word plus one, otherwise returns BreakIterator.DONE.
The offsets that are considered to be part of a word are the indexes of its characters,
as well as the index of its last character plus one.
If offset is the index of a low surrogate character, BreakIterator.DONE will be returned.
Valid range for offset is [0..textLength] (note the inclusive upper bound).
The returned value is within [offset..textLength] or BreakIterator.DONE.
final int shiftedOffset = offset - mOffsetShift;
checkOffsetIsValid(shiftedOffset);
if (isAfterLetterOrDigit(shiftedOffset)) {
if (mIterator.isBoundary(shiftedOffset)) {
return shiftedOffset + mOffsetShift;
} else {
return mIterator.following(shiftedOffset) + mOffsetShift;
}
} else {
if (isOnLetterOrDigit(shiftedOffset)) {
return mIterator.following(shiftedOffset) + mOffsetShift;
}
}
return BreakIterator.DONE;
|
private boolean | isAfterLetterOrDigit(int shiftedOffset)
if (shiftedOffset >= 1 && shiftedOffset <= mString.length()) {
final int codePoint = mString.codePointBefore(shiftedOffset);
if (Character.isLetterOrDigit(codePoint)) return true;
}
return false;
|
private boolean | isOnLetterOrDigit(int shiftedOffset)
if (shiftedOffset >= 0 && shiftedOffset < mString.length()) {
final int codePoint = mString.codePointAt(shiftedOffset);
if (Character.isLetterOrDigit(codePoint)) return true;
}
return false;
|
public int | preceding(int offset){@inheritDoc}
int shiftedOffset = offset - mOffsetShift;
do {
shiftedOffset = mIterator.preceding(shiftedOffset);
if (shiftedOffset == BreakIterator.DONE) {
return BreakIterator.DONE;
}
if (isOnLetterOrDigit(shiftedOffset)) {
return shiftedOffset + mOffsetShift;
}
} while (true);
|
public void | setCharSequence(java.lang.CharSequence charSequence, int start, int end)
mOffsetShift = Math.max(0, start - WINDOW_WIDTH);
final int windowEnd = Math.min(charSequence.length(), end + WINDOW_WIDTH);
if (charSequence instanceof SpannableStringBuilder) {
mString = ((SpannableStringBuilder) charSequence).substring(mOffsetShift, windowEnd);
} else {
mString = charSequence.subSequence(mOffsetShift, windowEnd).toString();
}
mIterator.setText(mString);
|