Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: URI Escape/Unescape Library?

15 views
Skip to first unread message

WJ

unread,
Feb 28, 2015, 4:34:39 PM2/28/15
to
> (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))

Gauche Scheme:

(use srfi-42)
(use gauche.lazy)
(define (unencode text)
(string-append-ec
(: s (map rxmatch-substring (lrxmatch #/\+|%..|[^+%]+/ text)))
(case (string-ref s 0)
((#\+) " ")
((#\%) (string (integer->char (string->number (substring s 1 3) 16))))
(else s))))

(unencode "Running+past+%41%42%43+again")
===>
"Running past ABC again"

WJ

unread,
Jan 13, 2016, 9:07:00 PM1/13/16
to
Why this is marked as abuse? It has been marked as abuse.
Report not abuse
MatzLisp (Ruby):

"Running+past+%41%42%43+again".gsub('+',' ').
gsub(/%../){|s| s[1,2].to_i(16).chr}
===>
"Running past ABC again"

--
[H]e was prosecuted ... for "denying" the gas chambers and the six million
figure. In July 1998 a Swiss court sentenced him to 15 months imprisonment,
and to pay a large fine, because of his writings. Rather than serve the
sentence, in August 2000 Graf went into exile. In 2001 he married a Russian
historian in Moscow. www.revisionists.com/revisionists/graf.html
0 new messages