Changeset 13256 in project


Ignore:
Timestamp:
02/12/09 00:47:11 (11 years ago)
Author:
Ivan Raikov
Message:

Added support for irregex.

Location:
release/3/content-type/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/3/content-type/trunk/content-type.scm

    r764 r13256  
    2525; 2045 and 822.
    2626
     27(define token)
    2728(define type   "[0-9A-Za-z-]+")
    2829(define pars   "\\s*(|;\\s*.*)$")
    29 (define token  "[^][()<>@,;:\\\\?=\"\\s]+")
    3030(define quoted "\"[^\"]*\"")
     31
     32(define irregex-feature?  (member 'irregex: (features)))
     33(define pcre-feature?     (member 'pcre: (features)))
     34
     35(cond
     36 (irregex-feature? (set! token "[^()<>@,;:\\\\?=\"\\s]+"))
     37 (pcre-feature?    (set! token "[^][()<>@,;:\\\\?=\"\\s]+")))
    3138
    3239(define-record content-type type subtype params)
    3340
    3441(define content-type-make
    35   (let ((expr (regexp (format #f "\\s*(~A)\\s*/\\s*(~A)~A" type type pars))))
     42  (let* ((rxstr (format #f (cond (irregex-feature? "^(Content-type:)?\\s*(~A)\\s*/\\s*(~A)~A")
     43                                 (pcre-feature?    "\\s*(~A)\\s*/\\s*(~A)~A"))
     44                        type type pars))
     45         (expr  (regexp rxstr #t)))
    3646    (lambda (line)
    3747      (and-let* ((match (string-match expr line)))
    3848        (call-with-current-continuation
    3949          (lambda (cont)
    40             (make-content-type (format #f "~(~A~)" (cadr match)) (format #f "~(~A~)" (caddr match))
    41               (make-content-type-params cont (cadddr match)))))))))
     50            (let ((match1 (cddr match)))
     51              (make-content-type (format #f "~(~A~)" (car match1)) (format #f "~(~A~)" (cadr match1))
     52                                 (make-content-type-params cont (caddr match1))))))))))
    4253
    4354(define make-content-type-params
    44   (let ((expr (regexp (format #f "^;\\s*(~A)\\s*=\\s*(~A|~A)~A" token token quoted pars))))
     55  (let* ((rxstr (format #f "^;\\s*(~A)\\s*=\\s*(~A|~A)~A" token token quoted pars))
     56         (expr (regexp rxstr)))
    4557    (lambda (cont line)
    4658      (if (equal? line "")
  • release/3/content-type/trunk/content-type.setup

    r2633 r13256  
    1 (if (not (memq 'pcre: (features)))
    2   (error (conc
    3     "This egg requires a CHICKEN compiled with PCRE support.\n"
    4     "See http://chicken.wiki.br:8080/content-type for more info.")))
     1;(if (not (memq 'pcre: (features)))
     2;  (error (conc
     3;    "This egg requires a CHICKEN compiled with PCRE support.\n"
     4;    "See http://chicken.wiki.br:8080/content-type for more info.")))
    55(compile -s -O2 -d1 content-type.scm)
    66(install-extension 'content-type '("content-type.so" "content-type.html") '((version 1.2) (documentation "content-type.html")))
Note: See TracChangeset for help on using the changeset viewer.