Changeset 12908 in project


Ignore:
Timestamp:
12/28/08 21:04:29 (11 years ago)
Author:
sjamaan
Message:

Rename char-sets and export them; make uri-{encode,decode}-string accept an optional char-set argument

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/uri-generic/trunk/uri-generic.scm

    r12857 r12908  
    5050   uri-relative-to uri-relative-from
    5151   uri-decode-string uri-encode-string
    52    uri-normalize-case uri-normalize-path-segments)
     52   uri-normalize-case uri-normalize-path-segments
     53
     54   char-set:gen-delims char-set:sub-delims
     55   char-set:uri-reserved char-set:uri-unreserved)
    5356
    5457(import chicken scheme extras data-structures)
     
    135138(define (hexdigit-char? c)    (and (char? c) (char-set-contains? char-set:hex-digit c)))
    136139
    137 (define (reserved-char? c)    (and (char? c) (char-set-contains? char-set:reserved c)))
    138 
    139 (define (unreserved-char? c)  (and (char? c) (char-set-contains? char-set:unreserved c)))
     140(define (reserved-char? c)    (and (char? c) (char-set-contains? char-set:uri-reserved c)))
     141
     142(define (unreserved-char? c)  (and (char? c) (char-set-contains? char-set:uri-unreserved c)))
    140143
    141144(define (scheme-char? c)      (and (char? c) (char-set-contains? char-set:scheme c)))
     
    231234;; Returns a 'pct-encoded' sequence of octets.
    232235;;
    233 (define (pct-encode char-list #!optional (char-set char-set:unreserved))
     236(define (pct-encode char-list char-set)
    234237  (define (hex-digit i)
    235238    (and (>= i 0) (< i 16) (car (string->list (sprintf "~X" i)))))
     
    245248;; Inverse operation: 'pct-decode' a sequence of octets.
    246249
    247 (define (pct-decode char-list #!optional (char-set char-set:unreserved))
     250(define (pct-decode char-list char-set)
    248251  (define (octet-decode h1 h2)
    249252    (string->number (list->string (list h1 h2)) 16))
     
    264267(define char-set:sub-delims (string->char-set "!$&'()*+,;="))
    265268
    266 (define char-set:reserved (char-set-union char-set:gen-delims char-set:sub-delims))
     269(define char-set:uri-reserved (char-set-union char-set:gen-delims char-set:sub-delims))
    267270
    268271;;  RFC3986, section 2.3
     
    271274;;
    272275
    273 (define char-set:unreserved
     276(define char-set:uri-unreserved
    274277  (char-set-union char-set:letter+digit (string->char-set "-_.~")))
    275278
     
    300303
    301304(define (uri-path-list->path pcl)
    302   (let ((cs (char-set-union char-set:unreserved (char-set #\/))))
     305  (let ((cs (char-set-union char-set:uri-unreserved (char-set #\/))))
    303306    (match pcl
    304307           (('/ . rst) (cons '/ (map (compose uri-char-list->string (cute pct-decode <> cs)) rst)))
     
    391394
    392395(define char-set:ipv-future
    393   (char-set-union char-set:unreserved char-set:sub-delims (char-set #\;)))
     396  (char-set-union char-set:uri-unreserved char-set:sub-delims (char-set #\;)))
    394397
    395398
     
    774777;;  Percent encoding and decoding
    775778
    776 (define (uri-encode-string str)
     779(define (uri-encode-string str #!optional (char-set (char-set-union
     780                                                     (char-set #\%)
     781                                                     char-set:uri-reserved)))
    777782  (let ((clst (string->list str)))
    778783    (uri-char-list->string
    779      (pct-encode clst (char-set-union (char-set #\%) char-set:reserved)))))
    780 
    781 (define (uri-decode-string str)
    782   (uri-char-list->string (pct-decode (uri-string->char-list str) char-set:full)))
     784     (pct-encode clst char-set))))
     785
     786(define (uri-decode-string str #!optional (char-set char-set:full))
     787  (uri-char-list->string (pct-decode (uri-string->char-list str) char-set)))
    783788   
    784789(define (uri-string->normalized-char-list str)
    785   (pct-decode (uri-string->char-list str)))
     790  (pct-decode (uri-string->char-list str) char-set:uri-unreserved))
    786791
    787792
Note: See TracChangeset for help on using the changeset viewer.