protected static String trimBracket(final String text, final char kind) {
        int left = 0;
        int right = text.length() - 1;
        char close = '}';
        switch (kind) {
            case '[':
                close = ']';
                break;
            case '(':
                close = ')';
                break;
        }
        while (text.charAt(left) == kind) {
            left++;
        }
        while (text.charAt(right) == close) {
            right--;
        }
        right++;
        return text.substring(left, right);
    }