@SuppressWarnings("DuplicatedCode")
  public static void scanWords(final ScanWordProcessor processor,
                               CharSequence chars,
                               final char @Nullable [] charArray,
                               final int startOffset,
                               final int endOffset,
                               final boolean mayHaveEscapes,
                               final IntPredicate isWordCodePoint) {
    int index = startOffset;
    boolean hasArray = charArray != null;
    ScanWordsLoop:
    while (true) {
      int startIndex = index;
      while (true) {
        if (index >= endOffset) break ScanWordsLoop;
        int codePoint = hasArray
                        ? Character.codePointAt(charArray, index, endOffset)
                        // no overload with endOffset, but it is highly unlikely that we go beyond it
                        : Character.codePointAt(chars, index);
        index += Character.charCount(codePoint);
        if (isWordCodePoint.test(codePoint)) {
          break;
        }
        if (mayHaveEscapes && codePoint == '\\') index++; //the next symbol is for escaping
        startIndex = index;
      }
      int endIndex = index;
      while (true) {
        if (index >= endOffset) break;
        int codePoint = hasArray ? Character.codePointAt(charArray, index, endOffset)
                                 : Character.codePointAt(chars, index);
        index += Character.charCount(codePoint);
        if (!isWordCodePoint.test(codePoint)) {
          break;
        }
        endIndex = index;
      }
      if (endIndex - startIndex > 100) continue; // Strange limit but we should have some!

      processor.run(chars, charArray, startIndex, endIndex);
    }
  }
@SuppressWarnings("DuplicatedCode")
  public static void scanWords(final ScanWordProcessor processor,
                               CharSequence chars,
                               final char @Nullable [] charArray,
                               final int startOffset,
                               final int endOffset,
                               final boolean mayHaveEscapes,
                               final IntPredicate isWordCodePoint)