public static void consumeAllOccurrences(@NotNull CharSequence documentText,
                                           @NotNull CharSequence textToFind,
                                           boolean matchExactWordsOnly,
                                           Consumer<? super TextRange> consumer) {
    String pattern = textToFind.toString();
    int length = pattern.length();
    StringSearcher searcher = new StringSearcher(pattern, true, true);
    searcher.processOccurrences(documentText, value -> {
      TextRange tr = TextRange.create(value, value + length);
      if (matchExactWordsOnly && isWordExpandableOutside(documentText, tr)) return true;
      consumer.consume(tr);
      return true;
    });
  }
public static void consumeAllOccurrences(@NotNull CharSequence documentText,
                                           @NotNull CharSequence textToFind,
                                           boolean matchExactWordsOnly,
                                           Consumer<? super TextRange> consumer)