guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: escaping characters


From: Ian Price
Subject: Re: escaping characters
Date: Fri, 02 Nov 2012 17:05:53 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Kejia$B[I2E(B <address@hidden> 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

[Prev in Thread] Current Thread [Next in Thread]