question: public int findNext ( ) { if ( findString . length ( ) == 0 || document . getLength ( ) - findString . length ( ) < startIndex ) { return - 1 ; } try { int nextMatch = 0 ; Segment text = new Segment ( ) ; text . setPartialReturn ( true ) ; int offset = startIndex ; int nleft = document . getLength ( ) - startIndex ; while ( nleft > 0 ) { document . getText ( offset , nleft , text ) ; char next = text . first ( ) ; for ( text . first ( ) ; next != Segment . DONE ; next = text . next ( ) ) { char current = text . current ( ) ; if ( current == matchUpperCase [ nextMatch ] || current == matchLowerCase [ nextMatch ] ) { nextMatch ++ ; if ( nextMatch == matchLowerCase . length ) { int foundIndex = text . getIndex ( ) - text . getBeginIndex ( ) + offset - matchLowerCase . length + 1 ; if ( matchType == MatchType . CONTAINS ) { return foundIndex ; } else if ( matchType == MatchType . STARTS_WITH ) { if ( ! isWordChar ( foundIndex - 1 ) ) { return foundIndex ; } } else if ( matchType == MatchType . FULL_WORD ) { if ( ! isWordChar ( foundIndex - 1 ) && ! isWordChar ( foundIndex + matchLowerCase . length ) ) { return foundIndex ; } } nextMatch = 0 ; } } else { nextMatch = 0 ; } } nleft -= text . count ; offset += text . count ; } return - 1 ; } catch ( BadLocationException e ) { throw new IndexOutOfBoundsException ( ) ; } }
target:  Attempts to find the next subsequence of the input sequence that matches the pattern. <p> This method starts at the beginning of the input sequence or, if a previous invocation of the method was successful and the matcher has not since been reset, at the first character not matched by the previous match.