Package org.eclipse.jface.text
Class MultiStringMatcher
java.lang.Object
org.eclipse.jface.text.MultiStringMatcher
Fast matcher to find the occurrences of any of a fixed set of constant strings. Supports finding
all (possibly overlapping) matches, or only the leftmost longest match.
- Since:
- 3.9
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A Builder for creating aMultiStringMatcher
.static interface
Describes a match result ofindexOf(CharSequence, int)
, giving access to the matched string and the offset in the text it was matched at. -
Method Summary
Modifier and TypeMethodDescriptionstatic MultiStringMatcher.Builder
builder()
Creates an initially emptyMultiStringMatcher.Builder
.static MultiStringMatcher
Creates aMultiStringMatcher
for the givensearchStrings
.find
(CharSequence text, int offset) Finds all occurrences of any of the search strings of theMultiStringMatcher
in the giventext
starting at the givenoffset
, including overlapping occurrences.void
find
(CharSequence text, int offset, Consumer<MultiStringMatcher.Match> matches) Finds all occurrences of any of the search strings of theMultiStringMatcher
in the giventext
starting at the givenoffset
, including overlapping occurrences.indexOf
(CharSequence text, int offset) Find the next occurrence of any of the search strings of theMultiStringMatcher
in the giventext
starting at the givenoffset
.static MultiStringMatcher.Match
indexOf
(CharSequence text, int offset, String... searchStrings) Finds the leftmost longest occurrence of any of the givensearchStrings
in thetext
starting at the givenoffset
.
-
Method Details
-
builder
Creates an initially emptyMultiStringMatcher.Builder
.- Returns:
- the
MultiStringMatcher.Builder
-
find
Finds all occurrences of any of the search strings of theMultiStringMatcher
in the giventext
starting at the givenoffset
, including overlapping occurrences.- Parameters:
text
- to search (notnull
)offset
- to start searching atmatches
-Consumer
all matches are fed to- Since:
- 3.10
-
find
Finds all occurrences of any of the search strings of theMultiStringMatcher
in the giventext
starting at the givenoffset
, including overlapping occurrences.- Parameters:
text
- to search (notnull
)offset
- to start searching at- Returns:
- a possibly empty list of matches
-
indexOf
Find the next occurrence of any of the search strings of theMultiStringMatcher
in the giventext
starting at the givenoffset
.Performs a simultaneous search for all the strings, returning the leftmost match. If multiple search strings match at the same index, the longest match is returned.
- Parameters:
text
- to search (notnull
)offset
- to start searching at- Returns:
- the leftmost longest match found, or
null
if no match was found.
-
indexOf
public static MultiStringMatcher.Match indexOf(CharSequence text, int offset, String... searchStrings) Finds the leftmost longest occurrence of any of the givensearchStrings
in thetext
starting at the givenoffset
.To match the same set of search strings repeatedly against texts it is more efficient to build and re-use a
MultiStringMatcher
.- Parameters:
text
- to search (notnull
)offset
- to start searching atsearchStrings
- to look for; non-null
and non-empty strings are ignored- Returns:
- a
MultiStringMatcher.Match
describing the match found, ornull
if no match was found or there are no non-null
non-emptysearchStrings
-
create
Creates aMultiStringMatcher
for the givensearchStrings
.If there are no non-
null
non-emptysearchStrings
, the returnedMultiStringMatcher
will never match anything.- Parameters:
searchStrings
- to look for; non-null
and non-empty strings are ignored- Returns:
- the
MultiStringMatcher
-