Class 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
    • Method Detail

      • find

        public void find​(CharSequence text,
                         int offset,
                         Consumer<MultiStringMatcher.Match> matches)
        Finds all occurrences of any of the search strings of the MultiStringMatcher in the given text starting at the given offset, including overlapping occurrences.
        Parameters:
        text - to search (not null)
        offset - to start searching at
        matches - 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 the MultiStringMatcher in the given text starting at the given offset, including overlapping occurrences.
        Parameters:
        text - to search (not null)
        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 the MultiStringMatcher in the given text starting at the given offset.

        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 (not null)
        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 given searchStrings in the text starting at the given offset.

        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 (not null)
        offset - to start searching at
        searchStrings - to look for; non-null and non-empty strings are ignored
        Returns:
        a MultiStringMatcher.Match describing the match found, or null if no match was found or there are no non-null non-empty searchStrings