Package org.eclipse.jface.text
Class MultiStringMatcher
- java.lang.Object
-
- org.eclipse.jface.text.MultiStringMatcher
-
public class MultiStringMatcher extends Object
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
Nested Classes Modifier and Type Class Description static interface
MultiStringMatcher.Builder
A Builder for creating aMultiStringMatcher
.static interface
MultiStringMatcher.Match
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MultiStringMatcher.Builder
builder()
Creates an initially emptyMultiStringMatcher.Builder
.static MultiStringMatcher
create(String... searchStrings)
Creates aMultiStringMatcher
for the givensearchStrings
.List<MultiStringMatcher.Match>
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.MultiStringMatcher.Match
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 Detail
-
builder
public static MultiStringMatcher.Builder builder()
Creates an initially emptyMultiStringMatcher.Builder
.- Returns:
- the
MultiStringMatcher.Builder
-
find
public 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.- Parameters:
text
- to search (notnull
)offset
- to start searching atmatches
-Consumer
all matches are fed to- Since:
- 3.10
-
find
public List<MultiStringMatcher.Match> 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.- Parameters:
text
- to search (notnull
)offset
- to start searching at- Returns:
- a possibly empty list of matches
-
indexOf
public MultiStringMatcher.Match indexOf(CharSequence text, int offset)
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
public static MultiStringMatcher create(String... searchStrings)
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
-
-