From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA16745; Sat, 27 Sep 2003 02:11:20 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA13431 for ; Sat, 27 Sep 2003 02:11:19 +0200 (MET DST) Received: from kraid.nerim.net (smtp-106-saturday.nerim.net [62.4.16.106]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8R0BFH20462 for ; Sat, 27 Sep 2003 02:11:15 +0200 (MET DST) Received: from karryall.dnsalias.org (karryall.dnsalias.org [62.4.18.180]) by kraid.nerim.net (Postfix) with ESMTP id EE3E040E35; Sat, 27 Sep 2003 02:11:12 +0200 (CEST) Received: by karryall.dnsalias.org (Postfix, from userid 500) id 246B71A0007; Sat, 27 Sep 2003 02:11:14 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16244.54690.54537.392805@karryall.dnsalias.org> Date: Sat, 27 Sep 2003 02:11:14 +0200 From: Olivier Andrieu To: Richard Jones Cc: caml-list@inria.fr Subject: Re: [Caml-list] Printf question In-Reply-To: <20030926180248.GA14053@redhat.com> References: <20030926180248.GA14053@redhat.com> X-Mailer: VM 7.17 under Emacs 21.2.1 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; andrieu:01 andrieu:01 caml-list:01 printf:01 printf:01 placeholder:01 formatter:01 fprintf:01 sprintf:01 string':01 handles:01 olivier:02 olivier:02 user-defined:02 module:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Richard Jones [Friday 26 September 2003] : > > I want to write a function which is a bit like Printf.printf, but > handles the %s placeholder differently. It needs to do SQL-style > escaping, eg: > > my_printf "The string: %s" "string with 'quotes'" > > would return the string: > > The string: 'string with ''quotes''' > > (hope I've got that right ...) > > Anyway, it looks like this should be possible, and possibly even quite > simple, with a custom formatter. You could use the %a format. See the Prinf module documentation : * `a': user-defined printer. Takes two arguments and apply the first one to `outchan' (the current output channel) and to the second argument. The first argument must therefore have type `out_channel -> 'b -> unit' and the second `'b'. The output produced by the function is therefore inserted in the output of `fprintf' at the current point. (that's for fprintf, for sprintf the printer would be of type `unit -> 'b -> string') -- Olivier ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners