private List<String> _testLastAndPrevious(RuleBasedBreakIterator rbbi, String text) { int p = rbbi.last(); int lastP = p; List<String> result = new ArrayList<String>(); if (p != text.length()) { errln("last() returned " + p + " instead of " + text.length()); } while (p != RuleBasedBreakIterator.DONE) { p = rbbi.previous(); if (p != RuleBasedBreakIterator.DONE) { if (p >= lastP) { errln( "previous() failed to move backward: previous() on position " + lastP + " yielded " + p); } result.add(0, text.substring(p, lastP)); } else { if (lastP != 0) { errln("previous() returned DONE prematurely: offset was " + lastP + " instead of 0"); } } lastP = p; } return result; }
private void doMultipleSelectionTest(RuleBasedBreakIterator iterator, String testText) { logln("Multiple selection test..."); RuleBasedBreakIterator testIterator = (RuleBasedBreakIterator) iterator.clone(); int offset = iterator.first(); int testOffset; int count = 0; do { testOffset = testIterator.first(); testOffset = testIterator.next(count); logln("next(" + count + ") -> " + testOffset); if (offset != testOffset) errln( "next(n) and next() not returning consistent results: for step " + count + ", next(n) returned " + testOffset + " and next() had " + offset); if (offset != RuleBasedBreakIterator.DONE) { count++; offset = iterator.next(); } } while (offset != RuleBasedBreakIterator.DONE); // now do it backwards... offset = iterator.last(); count = 0; do { testOffset = testIterator.last(); testOffset = testIterator.next(count); logln("next(" + count + ") -> " + testOffset); if (offset != testOffset) errln( "next(n) and next() not returning consistent results: for step " + count + ", next(n) returned " + testOffset + " and next() had " + offset); if (offset != RuleBasedBreakIterator.DONE) { count--; offset = iterator.previous(); } } while (offset != RuleBasedBreakIterator.DONE); }
@Override public int next() { int current = current(); int next = rules.next(); if (next == BreakIterator.DONE) return next; else next += workingOffset; char c = working.current(); int following = rules.next(); // lookahead if (following != BreakIterator.DONE) { following += workingOffset; if (rules.getRuleStatus() == 0 && laoSet.contains(c) && verifyPushBack(current, next)) { workingOffset = next - 1; working.setText( text.getText(), text.getStart() + workingOffset, text.getLength() - workingOffset); return next - 1; } rules.previous(); // undo the lookahead } return next; }