Kejia$B[I2E(B <w.ke...@gmail.com> writes:

> hi,
>
> is there a function that can escape of a string every character which
> is an escape character?
>
> thanks a lot.

Oleg Kiselyov has a function called 'make-char-quotator' which, I think,
does what you want. Guile does not technically export it, but you can
access it through (@@ (sxml simple) make-char-quotator)

(define make-char-quotator (@@ (sxml simple) make-char-quotator))

;; make-char-quotator takes an alist of character + string pairs
;; the character is the one to escape, and the string its replacement
;; it returns a function of two arguments, a string to escape, and a
;; port to write to.

(define my-weird-escaper
  (make-char-quotator
   '((#\' . "''")
     (#\~ . "\\~")
     (#\& . "{ampersand}"))))

(call-with-output-string
 (lambda (p)
   (my-weird-escaper
    "this is an example of how to use 'make-char-quotator' ~ it is not 
representative of any particular escaping mechanism I know of & I certainly 
hope none similar to it exists" p)))

outputs
    
"this is an example of how to use ''make$B!](Bchar$B!](Bquotator'' 
\\$(C!-(B it is not representative of any particular escaping mechanism I 
know of {ampersand} I certainly hope none similar to it exists"

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"

Reply via email to