quote_ident (PGconn)

    /*
     * call-seq:
     *    PGconn.quote_ident( str )
     *
     * Returns a SQL-safe identifier.
     */
    static VALUE
    pgconn_s_quote_ident(self, string)
        VALUE self;
        VALUE string;
    {
        char *str,*ptr;
        int i,j=0,len;
        VALUE result;

        Check_Type(string, T_STRING);

            ptr = RSTRING_PTR(string);
            len = RSTRING_LEN(string);
        str = ALLOCA_N(char, len * 2 + 2 + 1);
            str[j++] = '"';
            for(i = 0; i < len; i++) {
                    if(ptr[i] == '"')
                            str[j++] = '"';
                    else if(ptr[i] == '\0')
                            rb_raise(rb_ePGError, "Identifier cannot contain NULL bytes");
                    str[j++] = ptr[i];
            }
            str[j++] = '"';
        result = rb_str_new(str, j);
        OBJ_INFECT(result, string);
        return result;
    }