/** * <p> * Sets the position in the target text at which the next search will start. * This method clears any previous match. * </p> * @param position position from which to start the next search * @exception IndexOutOfBoundsException thrown if argument position is out * of the target text range. * @see #getIndex * @stable ICU 2.8 */ public void setIndex(int position) { if (position < search_.beginIndex() || position > search_.endIndex()) { throw new IndexOutOfBoundsException( "setIndex(int) expected position to be between " + search_.beginIndex() + " and " + search_.endIndex()); } search_.reset_ = false; search_.setMatchedLength(0); search_.matchedIndex_ = DONE; }
private boolean search(int startIdx, Match m) { || startIdx < search_.beginIndex() || startIdx > search_.endIndex()) { throw new IllegalArgumentException("search(" + startIdx + ", m) - expected position to be between " + search_.beginIndex() + " and " + search_.endIndex());
|| startIdx < search_.beginIndex() || startIdx > search_.endIndex()) { throw new IllegalArgumentException("searchBackwards(" + startIdx + ", m) - expected position to be between " + search_.beginIndex() + " and " + search_.endIndex());
int startIdx = search_.beginIndex(); if (index == startIdx || matchindex == startIdx) {
/** * {@inheritDoc} * @stable ICU 2.8 */ @Override protected int handlePrevious(int position) { if (pattern_.CELength_ == 0) { search_.matchedIndex_ = search_.matchedIndex_ == DONE ? getIndex() : search_.matchedIndex_; if (search_.matchedIndex_ == search_.beginIndex()) { setMatchNotFound(); } else { search_.matchedIndex_--; textIter_.setOffset(search_.matchedIndex_); search_.setMatchedLength(0); } } else { textIter_.setOffset(position); if (search_.isCanonicalMatch_) { // *could* use exact match here since extra accents *not* allowed! handlePreviousCanonical(); } else { handlePreviousExact(); } } return search_.matchedIndex_; }
/** * Returns the first index at which the string text matches the search * pattern. The iterator is adjusted so that its current index (as * returned by {@link #getIndex()}) is the match position if one * * was found. * If a match is not found, {@link #DONE} will be returned and * the iterator will be adjusted to the index {@link #DONE}. * @return The character index of the first match, or * {@link #DONE} if there are no matches. * * @see #getIndex * @stable ICU 2.0 */ public final int first() { int startIdx = search_.beginIndex(); setIndex(startIdx); return handleNext(startIdx); }
/** * Resets the iteration. * Search will begin at the start of the text string if a forward * iteration is initiated before a backwards iteration. Otherwise if a * backwards iteration is initiated before a forwards iteration, the * search will begin at the end of the text string. * * @stable ICU 2.0 */ public void reset() { setMatchNotFound(); setIndex(search_.beginIndex()); search_.isOverlap_ = false; search_.isCanonicalMatch_ = false; search_.elementComparisonType_ = ElementComparisonType.STANDARD_ELEMENT_COMPARISON; search_.isForwardSearching_ = true; search_.reset_ = true; }
/** * {@inheritDoc} * @stable ICU 2.8 */ @Override public int getIndex() { int result = textIter_.getOffset(); if (isOutOfBounds(search_.beginIndex(), search_.endIndex(), result)) { return DONE; } return result; }