public static int skipBrackets(String args, int startIndex, int len, char bracket) {
        char closeBracket = getCloseBracket(bracket);

        Deque<Character> stack = new ArrayDeque<>();
        for (int i = startIndex + (startIndex < len && args.charAt(startIndex) == bracket ? 1 : 0); i < len; i++) {
            char ch = args.charAt(i);
            if (isQuote(ch)) {
                i = skipQuotedString(args, i, len, ch) - 1;
            } else if (isOpenBracket(ch)) {
                stack.push(closeBracket);
                closeBracket = getCloseBracket(ch);
            } else if (ch == closeBracket) {
                if (stack.isEmpty()) {
                    return i + 1;
                } else {
                    closeBracket = stack.pop();
                }
            } else if (i + 1 < len) {
                char nextChar = args.charAt(i + 1);
                if (ch == '-' && nextChar == '-') {
                    i = skipSingleLineComment(args, i + 2, len) - 1;
                } else if (ch == '/' && nextChar == '*') {
                    i = skipMultiLineComment(args, i + 2, len) - 1;
                }
            }
        }

        throw new IllegalArgumentException(
                format("Missing '%s' for '%s' at position %d", closeBracket, bracket, startIndex));
    }
Skip brackets and content inside with consideration of nested brackets,
quoted string and comments.

@param args       non-null string to scan
@param startIndex start index, optionally index of the opening bracket
@param len        end index, usually length of the given string
@param bracket    opening bracket supported by {@link #isOpenBracket(char)}
@return index next to matched closing bracket
@throws IllegalArgumentException when missing closing bracket(s)
clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseUtils.java