Changeset 11913 in project


Ignore:
Timestamp:
09/06/08 23:31:26 (13 years ago)
Author:
sjamaan
Message:

rename read-token to parse-token (and similar for other procedures like it)

Location:
release/4/intarweb/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/intarweb/trunk/header-parsers.scm

    r11912 r11913  
    6565    (let loop ((result '())
    6666               (start-pos 0)   ; Where the current header value starts
    67                (read-pos 0))       ; Where the reading position starts
    68       (or (and-let* (((< read-pos len))
    69                      (pos (string-index value (char-set #\, #\") read-pos)))
     67               (search-pos 0)) ; Where the searching starts
     68      (or (and-let* (((< search-pos len))
     69                     (pos (string-index value (char-set #\, #\") search-pos)))
    7070            (if (char=? #\, (string-ref value pos))
    7171                (loop (cons (string-copy value start-pos pos) result) (add1 pos) (add1 pos))
     
    9090;; char-set where we should stop.  Returns two values: the token or #f if
    9191;; there is no token left, and the position on which the token ends.
    92 (define (read-token value start-pos stop-char-set)
     92(define (parse-token value start-pos stop-char-set)
    9393  (if (>= start-pos (string-length value))
    9494      (values #f start-pos)
     
    103103                    ;; Found the double quote? Recurse on the remainder
    104104                    (receive (rest final-pos)
    105                       (read-token value (add1 end-pos) stop-char-set)
     105                      (parse-token value (add1 end-pos) stop-char-set)
    106106                      (values (string-append
    107107                               (string-trim-both
     
    123123  (update-header-contents! name (list (vector contents '())) headers))
    124124
    125 (define (read-parameters string start-pos param-parsers)
     125(define (parse-parameters string start-pos param-parsers)
    126126  (let loop ((start-pos start-pos)
    127127             (params '()))
    128128    (receive (key pos)
    129       (read-token string start-pos (char-set #\; #\=))
     129      (parse-token string start-pos (char-set #\; #\=))
    130130      (if key
    131131          (if (and (< pos (string-length string)) (char=? (string-ref string pos) #\=))
    132132              (receive (value pos)
    133                 (read-token string (add1 pos) (char-set #\;))
     133                (parse-token string (add1 pos) (char-set #\;))
    134134                (let ((key (string->symbol (string-downcase key))))
    135135                  ;; In case of no value ("foo="), use the empty string as value
     
    141141          (values (reverse params) pos)))))
    142142
    143 (define (read-value+parameters string start-pos value-parser param-parsers)
     143(define (parse-value+parameters string start-pos value-parser param-parsers)
    144144  (receive (value pos)
    145     (read-token string start-pos (char-set #\;))
     145    (parse-token string start-pos (char-set #\;))
    146146    (if (not value)
    147147        (values #f pos) ;; XXX this is wrong and not expected by the caller!
    148148        (receive (params pos)
    149           (read-parameters string (add1 pos) param-parsers)
     149          (parse-parameters string (add1 pos) param-parsers)
    150150          (values (vector (value-parser value) params) pos)))))
    151151
     
    153153  (lambda (entry)
    154154    (receive (type+params pos)
    155       (read-value+parameters entry 0 value-parser parameter-parsers)
     155      (parse-value+parameters entry 0 value-parser parameter-parsers)
    156156      type+params)))
    157157
     
    175175(define (key/values key/value-parsers)
    176176  (lambda (k/v)
    177     ;; We're abusing read-parameters here to read value
     177    ;; We're abusing parse-parameters here to read value
    178178    ;; instead of params.  This is weird, but it works :)
    179179    (receive (key+value pos)
    180       (read-parameters k/v 0 key/value-parsers)
     180      (parse-parameters k/v 0 key/value-parsers)
    181181      (car key+value))))
    182182
     
    264264;; This too
    265265(define (pragma-parser name value headers)
    266   (update-header-contents! name (read-parameters value 0 `()) headers))
     266  (update-header-contents! name (parse-parameters value 0 `()) headers))
    267267
    268268;; This one includes q parser
    269269(define (te-parser name value headers)
    270   (update-header-contents! name (read-parameters value 0 `((q . ,quality-parser))) headers))
     270  (update-header-contents! name (parse-parameters value 0 `((q . ,quality-parser))) headers))
    271271
    272272;; Cookie headers are also braindead: there can be several cookies in one header,
     
    277277;; considered to apply to all cookies that follow.
    278278;;
    279 ;; This code is a bit of a hack in the way it abuses read-parameters
     279;; This code is a bit of a hack in the way it abuses parse-parameters
    280280(define (cookie-parser name value headers)
    281281  ;; Get all attributes (dollar-prefixed params) and remaining cookies & params
     
    285285          pairs))
    286286  (receive (params pos)
    287     (read-parameters value 0 `(($version . ,string->number)
     287    (parse-parameters value 0 `(($version . ,string->number)
    288288                               ($port . ,string->number)))
    289289    (receive (global-attrs remaining)
  • release/4/intarweb/trunk/intarweb.scm

    r11910 r11913  
    6060
    6161   ;; http-header-parsers
    62    split-multi-header unknown-header-parser single multiple read-token
     62   split-multi-header unknown-header-parser single multiple parse-token
    6363   header-contents header-values header-list-ref
    6464   get-quality get-value get-params get-param
     
    7171  (require-library srfi-1 srfi-13 regex regex-case base64 defstruct uri-generic)
    7272
    73   (import (except extras read-token) ports data-structures
     73  (import extras ports data-structures
    7474          srfi-1 srfi-13 srfi-14 regex regex-case (prefix base64 base64:)
    7575          defstruct uri-generic)
Note: See TracChangeset for help on using the changeset viewer.