Changeset 12989 in project


Ignore:
Timestamp:
01/11/09 23:44:32 (11 years ago)
Author:
sjamaan
Message:

Just had a revelation that query-separator keyword args are never going to work; when layers upon layers of code all call uri-common eventually, the query-separator would have to be carried through all the time. This is unacceptable. parameterize suddenly became a lot less ugly on second thought :)

File:
1 edited

Legend:

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

    r12987 r12989  
    7070
    7171;; A common URI is a generic URI plus stored decoded versions of most components
    72 ;; It also contains a query separator because we need that every time
    73 ;; we encode/decode between a uri-generic and uri-common object.
    74 ;;
    75 ;; TODO: This results in horrible code, reproducing the query bit
    76 ;;  every time.  Find a way to clean this up, without requiring the
    77 ;;  user to wrap every call to any uri-common procedure that delegates
    78 ;;  to uri-generic in a PARAMETERIZE call...  (besides this being very
    79 ;;  ugly, the user shouldn't need to know when we use uri-generic
    80 ;;  internally and when not)
    8172(defstruct URI-common
    82   generic username password host path query fragment
    83   query-separator)
     73  generic username password host path query fragment)
    8474
    8575(define-record-printer (URI-common x out)
    86   (fprintf out "#(URI-common scheme=~S host=~S path=~S query=~S fragment=~S query-separator=~S)"
     76  (fprintf out "#(URI-common scheme=~S host=~S path=~S query=~S fragment=~S"
    8777           (uri-scheme (URI-common-generic x))
    8878           (URI-common-host x)
    8979           (URI-common-path x)
    9080           (URI-common-query x)
    91            (URI-common-fragment x)
    92            (URI-common-query-separator x)))
     81           (URI-common-fragment x)))
    9382
    9483(define (decode-string* s)
    9584  (and s (uri-decode-string s)))
    9685
    97 (define (uri-common-reference u #!key (query-separator (form-urlencoded-separator)))
    98   (uri-generic->uri-common (uri-reference u) query-separator: query-separator))
    99 (define (absolute-uri-common u #!key (query-separator (form-urlencoded-separator)))
    100   (uri-generic->uri-common (absolute-uri u) query-separator: query-separator))
    101 
    102 (define (uri-generic->uri-common uri #!key (query-separator (form-urlencoded-separator)))
     86(define (uri-common-reference u)
     87  (uri-generic->uri-common (uri-reference u)))
     88(define (absolute-uri-common u)
     89  (uri-generic->uri-common (absolute-uri u)))
     90
     91(define (uri-generic->uri-common uri)
    10392  (make-URI-common generic: uri
    10493                   username: (decode-string* (uri-username uri))
     
    10695                   host:     (decode-string* (uri-host uri))
    10796                   path:     (decode-path (uri-path uri))
    108                    query:    (form-urldecode (uri-query uri)
    109                                              separator: query-separator)
    110                    fragment: (decode-string* (uri-fragment uri))
    111                    query-separator: query-separator))
     97                   query:    (form-urldecode (uri-query uri))
     98                   fragment: (decode-string* (uri-fragment uri))))
    11299
    113100(define (uri-common->uri-generic uri)
     
    148135    (lambda (uc #!key
    149136                (scheme unset) (username unset) (password unset) (host unset)
    150                 (path unset) (query unset) (fragment unset)
    151                 (query-separator unset))
     137                (path unset) (query unset) (fragment unset))
    152138      (let ((uc (update-URI-common uc))) ;; new copy
    153139        (unless (eq? scheme unset)
     
    174160                          path: (encode-path path)))
    175161          (URI-common-path-set! uc path))
    176         ;; First the separator, so we can decode the query, if needed
    177         (unless (eq? query-separator unset)
    178           (URI-common-query-separator-set! uc query-separator))
    179162        (unless (eq? query unset)
    180163          (URI-common-generic-set!
    181164           uc (update-uri (URI-common-generic uc)
    182                           query: (form-urlencode
    183                                   query
    184                                   separator: (URI-common-query-separator uc))))
     165                          query: (form-urlencode query)))
    185166          (URI-common-query-set! uc query))
    186167        (unless (eq? fragment unset)
     
    283264  (apply uri->string (URI-common-generic uri) args))
    284265
    285 ;; XXX: The query-separator gets dropped to the floor here, resetting it
    286266(define (wrap proc)
    287267  (lambda args
Note: See TracChangeset for help on using the changeset viewer.