private static int lastIndexOf(@NotNull CharSequence buffer, @NotNull String pattern, int maxIndex, boolean ignoreCase) {
    int patternLength = pattern.length();
    int end = buffer.length() - patternLength;
    if (maxIndex > end) {
      maxIndex = end;
    }
    for (int i = maxIndex; i >= 0; i--) {
      boolean found = true;
      for (int j = 0; j < patternLength; j++) {
        if (ignoreCase) {
          if (!StringUtil.charsEqualIgnoreCase(pattern.charAt(j), buffer.charAt(i + j))) {
            found = false;
            break;
          }
        }
        else {
          if (pattern.charAt(j) != buffer.charAt(i + j)) {
            found = false;
            break;
          }
        }
      }
      if (found) {
        return i;
      }
    }
    return -1;
  }
private static int lastIndexOf(@NotNull CharSequence buffer, @NotNull String pattern, int maxIndex, boolean ignoreCase)