From 9e71b351d4c3e003043a728dc774898d30e7e19b Mon Sep 17 00:00:00 2001 From: vibr Date: Thu, 14 Oct 2004 17:14:44 +0000 Subject: [PATCH] *remove UNESCAPE-URI, HEX-DIGIT? *move HEXCHAR->INT to url.scm --- scheme/lib/uri.scm | 58 ---------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/scheme/lib/uri.scm b/scheme/lib/uri.scm index 15588fc..a76ebdd 100644 --- a/scheme/lib/uri.scm +++ b/scheme/lib/uri.scm @@ -15,64 +15,6 @@ ;;; General Web page of URI pointers. -;;; Caution: -;;; Don't use this proc until *after* you've parsed the URL -- unescaping -;;; might introduce reserved chars (like slashes and colons) that could -;;; blow your parse. - -(define (unescape-uri s . maybe-start/end) - (let-optionals maybe-start/end ((start 0) - (end (string-length s))) - (let* ((esc-seq? (lambda (i) (and (< (+ i 2) end) - (char=? (string-ref s i) #\%) - (hex-digit? (string-ref s (+ i 1))) - (hex-digit? (string-ref s (+ i 2)))))) - (hits (let lp ((i start) (hits 0)) ; count # of esc seqs. - (if (< i end) - (if (esc-seq? i) - (lp (+ i 3) (+ hits 1)) - (lp (+ i 1) hits)) - hits)))) - - (if (and (zero? hits) (zero? start) (= end (string-length s))) - s - (let* ((nlen (- (- end start) (* hits 2))) ; the new length - ; of the - ; unescaped - ; string stores - ; the result - (ns (make-string nlen))) - - (let lp ((i start) (j 0)) ; sweep over the string - (if (< j nlen) - (lp (cond - ((esc-seq? i) ; unescape - ; escape-sequence - (string-set! ns j - (let ((d1 (string-ref s (+ i 1))) - (d2 (string-ref s (+ i 2)))) - (ascii->char (+ (* 16 (hexchar->int d1)) - (hexchar->int d2))))) - (+ i 3)) - (else (string-set! ns j (string-ref s i)) - (+ i 1))) - (+ j 1)))) - ns))))) - -(define hex-digit? - (let ((hex-digits (string->char-set "0123456789abcdefABCDEF"))) - (lambda (c) (char-set-contains? hex-digits c)))) - -; make use of the fact that numbers and characters are in order in the ascii table -(define (hexchar->int c) - (- (char->ascii c) - (if (char-numeric? c) - (char->ascii #\0) - (- (if (char-upper-case? c) - (char->ascii #\A) - (char->ascii #\a)) - 10)))) - (define int->hexchar (let ((table '#(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\A #\B #\C #\D #\E #\F)))