Re: URI Escape/Unescape Library?
- From: Robert Uhl <ruhlNO@xxxxxxxxxxx>
- Date: Tue, 31 May 2005 14:49:35 -0600
Lars Brinkhoff <lars.spam@xxxxxxxxxx> writes:
>
> > I also replaced the loop and length with DOTIMES. The behaviour
> > appears to be the same.
>
> ...I believe you shouldn't rely on being able to modify the loop
> variable (i below). CLHS says:
>
> It is implementation-dependent whether dotimes establishes a new
> binding of var on each iteration or whether it establishes a
> binding for var once at the beginning and then assigns it on any
> subsequent iterations.
Doh! That's what I get for just writing a bit of test code instead of
reading the spec. Gotta get out of that habit.
> You could use with-input-from-string to read characters from text.
Nah--it doesn't really make sense conceptually to me to be reading
characters instead of iterating over the string. It's probably not all
that efficient, either, not that _that_ really matters. Here's the
(probable) final version.
(defun unencode (text)
"decode URL-escaped values: + is replaced with space; %nn with the
appropriate ASCII char"
(declare (string text))
(with-output-to-string (output)
(let ((len (length text)))
(loop with i = 0
with c do
(when (>= i len) (return))
(setf c (elt text i))
(cond ((equal c #\+) (setf c #\Space))
((equal c #\%)
(setf c (code-char
(read-from-string
(concatenate 'string "#x"
(subseq text (1+ i) (+ i 3))))))
(incf i 2)))
(write-char c output)))
output))
--
Robert Uhl <http://public.xdi.org/=ruhl>
Kristus is riesen! Weerelk, Hi is riesen!
.
- References:
- URI Escape/Unescape Library?
- From: Robert Uhl
- Re: URI Escape/Unescape Library?
- From: Andreas Thiele
- Re: URI Escape/Unescape Library?
- From: Lars Brinkhoff
- Re: URI Escape/Unescape Library?
- From: Robert Uhl
- Re: URI Escape/Unescape Library?
- From: Lars Brinkhoff
- URI Escape/Unescape Library?
- Prev by Date: Re: URI Escape/Unescape Library?
- Next by Date: Re: Overlord programs
- Previous by thread: Re: URI Escape/Unescape Library?
- Next by thread: Re: URI Escape/Unescape Library?
- Index(es):
Relevant Pages
|
Loading