/** * Returns the text that was matched by the most recent call to * {@link #first}, {@link #next}, {@link #previous}, or {@link #last}. * If the iterator is not pointing at a valid match (e.g. just after * construction or after {@link #DONE} has been returned, * returns an empty string. * * @return the substring in the target test of the most recent match, * or null if there is no match currently. * @see #first * @see #next * @see #previous * @see #last * @stable ICU 2.0 */ public String getMatchedText() { if (search_.matchedLength() > 0) { int limit = search_.matchedIndex_ + search_.matchedLength(); StringBuilder result = new StringBuilder(search_.matchedLength()); CharacterIterator it = search_.text(); it.setIndex(search_.matchedIndex_); while (it.getIndex() < limit) { result.append(it.current()); it.next(); } it.setIndex(search_.matchedIndex_); return result.toString(); } return null; }
matchindex += search_.matchedLength() - 2;
int index = getIndex(); // offset = getOffset() in ICU4C int matchindex = search_.matchedIndex_; int matchlength = search_.matchedLength(); search_.reset_ = false; if (search_.isForwardSearching_) {
if (search_.matchedLength() <= 0) {
textOffset = search_.matchedIndex_ + search_.matchedLength() - 1; } else {
/** * Returns the length of text in the string which matches the search * pattern. This call returns a valid result only after a successful call * to {@link #first}, {@link #next}, {@link #previous}, or {@link #last}. * Just after construction, or after a searching method returns * {@link #DONE}, this method will return 0. * * @return The length of the match in the target text, or 0 if there * is no match currently. * @see #first * @see #next * @see #previous * @see #last * @stable ICU 2.0 */ public int getMatchLength() { return search_.matchedLength(); }