public class WordIterator extends Object implements Selection.PositionIterator
BreakIterator.getWordInstance()
, and caches CharSequence
for performance reasons.
Also provides methods to determine word boundaries.
DONE
Constructor and Description |
---|
WordIterator()
Constructs a WordIterator using the default locale.
|
WordIterator(Locale locale)
Constructs a new WordIterator for the specified locale.
|
Modifier and Type | Method and Description |
---|---|
int |
following(int offset) |
int |
getBeginning(int offset)
If
offset is within a word, returns the index of the first character of that
word, otherwise returns BreakIterator.DONE. |
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. |
int |
preceding(int offset) |
void |
setCharSequence(CharSequence charSequence,
int start,
int end) |
public WordIterator()
public WordIterator(Locale locale)
locale
- The locale to be used when analysing the text.public void setCharSequence(CharSequence charSequence, int start, int end)
public int preceding(int offset)
preceding
in interface Selection.PositionIterator
public int following(int offset)
following
in interface Selection.PositionIterator
public int getBeginning(int offset)
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.IllegalArgumentException
- is offset is not valid.public int getEnd(int offset)
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.IllegalArgumentException
- is offset is not valid.