@Override public int first() { fIndex= fIterator.first(); return fIndex; }
@Override public int last() { fIndex= fIterator.last(); return fIndex; }
@Override public int preceding(int offset) { if (offset == getText().getBeginIndex()) return DONE; if (isBoundary(offset - 1)) return offset - 1; int previous= offset - 1; do { previous= fIterator.preceding(previous); } while (!isBoundary(previous)); int last= DONE; while (previous < offset) { last= previous; previous= following(previous); } return last; }
@Override public int following(int offset) { // work around too eager IAEs in standard implementation if (offset == getText().getEndIndex()) return DONE; int next= fIterator.following(offset); if (next == DONE) return DONE; // TODO deal with complex script word boundaries // Math.min(offset + run.length, next) does not work // since BreakIterator.getWordInstance considers _ as boundaries // seems to work fine, however Run run= consumeRun(offset); return offset + run.length; }
@Override public void setText(String newText) { setText((CharSequence) newText); }
@Override public int next() { fIndex= following(fIndex); return fIndex; }
@Override public int previous() { fIndex= preceding(fIndex); return fIndex; }
/** * Creates a new word iterator. */ public JavaWordIterator() { fIterator= new JavaBreakIterator(); first(); }
@Override public CharacterIterator getText() { return fIterator.getText(); }
/** * Consumes a run of characters at the limits of which we introduce a break. * @param offset the offset to start at * @return the run that was consumed */ private Run consumeRun(int offset) { // assert offset < length char ch= fText.charAt(offset); int length= fText.length(); Run run= getRun(ch); while (run.consume(ch) && offset < length - 1) { offset++; ch= fText.charAt(offset); } return run; }
public int preceding(int offset) { if (offset == getText().getBeginIndex()) return DONE; if (isBoundary(offset - 1)) return offset - 1; int previous= offset - 1; do { previous= fIterator.preceding(previous); } while (!isBoundary(previous)); int last= DONE; while (previous < offset) { last= previous; previous= following(previous); } return last; }
@Override public int following(int offset) { // work around too eager IAEs in standard implementation if (offset == getText().getEndIndex()) return DONE; int next= fIterator.following(offset); if (next == DONE) return DONE; // TODO deal with complex script word boundaries // Math.min(offset + run.length, next) does not work // since BreakIterator.getWordInstance considers _ as boundaries // seems to work fine, however Run run= consumeRun(offset); return offset + run.length; }
@Override public void setText(String newText) { setText((CharSequence) newText); }
@Override public int next() { fIndex= following(fIndex); return fIndex; }
@Override public int previous() { fIndex= preceding(fIndex); return fIndex; }
/** * Creates a new word iterator. */ public JavaWordIterator() { fIterator= new JavaBreakIterator(); first(); }
@Override public CharacterIterator getText() { return fIterator.getText(); }
/** * Consumes a run of characters at the limits of which we introduce a break. * @param offset the offset to start at * @return the run that was consumed */ private Run consumeRun(int offset) { // assert offset < length char ch= fText.charAt(offset); int length= fText.length(); Run run= getRun(ch); while (run.consume(ch) && offset < length - 1) { offset++; ch= fText.charAt(offset); } return run; }
@Override public int preceding(int offset) { if (offset == getText().getBeginIndex()) return DONE; if (isBoundary(offset - 1)) return offset - 1; int previous= offset - 1; do { previous= fIterator.preceding(previous); } while (!isBoundary(previous)); int last= DONE; while (previous < offset) { last= previous; previous= following(previous); } return last; }