Class StringMatcher

java.lang.Object
org.languagetool.rules.patterns.StringMatcher

public abstract class StringMatcher extends Object
An object encapsulating a text pattern and the way it's matched (case-sensitivity / regular expression), plus some optimizations over standard regular expression matching.
Since:
5.3
  • Field Details

    • pattern

      final String pattern
    • caseSensitive

      final boolean caseSensitive
    • isRegExp

      final boolean isRegExp
    • MAX_MATCH_LENGTH

      public static final int MAX_MATCH_LENGTH
      See Also:
  • Constructor Details

    • StringMatcher

      private StringMatcher(String pattern, boolean isRegExp, boolean caseSensitive)
  • Method Details

    • getPossibleValues

      @Nullable public abstract Set<String> getPossibleValues()
      Returns:
      all values that this matcher can possibly accept (e.g. extracted from regexps like "foo|bar"), or null if it's not possible to determine those.
    • matches

      public abstract boolean matches(String s)
      Returns:
      whether the given string is accepted by this matcher.
    • regexp

      public static StringMatcher regexp(String pattern)
      Create a case-sensitive regexp matcher.
      Since:
      5.6
    • create

      public static StringMatcher create(String pattern, boolean isRegExp, boolean caseSensitive)
    • stringEquals

      @NotNull private static StringMatcher stringEquals(String pattern, boolean isRegExp, boolean caseSensitive)
    • getRequiredSubstrings

      @Nullable static Substrings getRequiredSubstrings(String regexp)
      Returns:
      the substrings that any text would necessarily contain or start/end with if it matches the given regexp, or null if no such substrings can be found
    • getPossibleRegexpValues

      @Nullable static Set<String> getPossibleRegexpValues(String regexp)
      Returns:
      all strings that the given regexp can ever match, or null if such set couldn't be enumerated