class QuoteIdentFunction {

    private static final FunctionName FQNAME = new FunctionName(PgCatalogSchemaInfo.NAME, "quote_ident");

    public static void register(Functions.Builder module) {
        module.add(
            Signature.scalar(
                FQNAME,
                DataTypes.STRING.getTypeSignature(),
                DataTypes.STRING.getTypeSignature()
            ).withFeature(Scalar.Feature.NULLABLE),
            (signature, boundSignature) ->
                new UnaryScalar<>(
                    signature,
                    boundSignature,
                    DataTypes.STRING,
                    QuoteIdentFunction::maybeQuoteExpression
                )
        );
    }

    /**
     * Similar to {@link Identifiers#quoteIfNeeded}.
     * The main difference is that for subscript expressions, this method will quote the base(root) columns only
     * when it's needed.
     */
    @VisibleForTesting
    static String maybeQuoteExpression(String expression) {
        int length = expression.length();
        if (length == 0) {
            return "\"\"";
        }
        if (isKeyWord(expression)) {
            return '"' + expression + '"';
        }
        StringBuilder sb = new StringBuilder();
        boolean addQuotes = false;
        int subscriptStartPos = -1;
        for (int i = 0; i < length; i++) {
            char c = expression.charAt(i);
            if (c == '"') {
                sb.append('"');
            }
            sb.append(c);
            if (subscriptStartPos == -1) {
                if (c == '[' && i + 1 < length && expression.charAt(i + 1) == '\'') {
                    subscriptStartPos = i;
                } else {
                    addQuotes = addQuotes || charIsOutsideSafeRange(i, c);
                }
            }
        }
        if (addQuotes) {
            sb.insert(0, '"');
            if (subscriptStartPos == -1) {
                sb.append('"');
            } else {
                sb.insert(subscriptStartPos + 1, '"');
            }
        }
        return sb.toString();
    }

    private static boolean charIsOutsideSafeRange(int i, char c) {<FILL_FUNCTION_BODY>}
}

        if (i == 0) {
            return c != '_' && (c < 'a' || c > 'z');
        }
        return c != '_' && (c < 'a' || c > 'z') && (c < '0' || c > '9');
    
<no_super_class>