public class StringSearcher<MATCHRESULT>
extends java.lang.Object
StringMatcher
.
NOTE: Instances of this class are thread-safe.
Constructor and Description |
---|
StringSearcher(DfaState<MATCHRESULT> matcher,
DfaState<?> reverseFinder)
Create a new StringSearcher.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
findAndReplace(java.lang.String src,
ReplacementSelector<? super MATCHRESULT> replacer)
Replace all occurrences of patterns in a string
|
StringMatchIterator<MATCHRESULT> |
searchString(java.lang.String src)
Search the string for all occurrences of the patterns that this searcher finds
|
public StringSearcher(DfaState<MATCHRESULT> matcher, DfaState<?> reverseFinder)
matcher
- A DFA that matches the patterns being searched forreverseFinder
- A DFA that can be applied to a string backwards to
find all the places where matches start. See DfaBuilder.buildReverseFinder()
public StringMatchIterator<MATCHRESULT> searchString(java.lang.String src)
src
- String to searchStringMatchIterator
that returns all (non-overlapping) matchespublic java.lang.String findAndReplace(java.lang.String src, ReplacementSelector<? super MATCHRESULT> replacer)
The string is searched for all (non-overlapping) occurrences of patterns in this searcher, for each occurrence, the provided replacer is called to supply a replacement value for that part of the string. If it returns null, that part of the string remains unchanged. If it returns a String, then the pattern occurrence will be replaced with the string returned.
src
- the String to searchreplacer
- the ReplacementSelector
that provides new values for matches in the string