private static boolean isTrailingSpace(@NotNull CharSequence text, int end) {
    if (end < 0) return false;
    if (end == text.length()) return false;
    if (!isWhiteSpace(text.charAt(end))) return false;

    while (end < text.length()) {
      char c = text.charAt(end);
      if (c == '\n') return true;
      if (!isWhiteSpace(c)) return false;
      end++;
    }
    return true;
  }
private static boolean isTrailingSpace(@NotNull CharSequence text, int end)