From 67d804af6271e2968c82238ac5a452f8eaef3d11 Mon Sep 17 00:00:00 2001 From: Matthias Felleisen Date: Tue, 27 Apr 2010 10:26:24 -0400 Subject: [PATCH 1/2] changed the names for batch-io functions following SK's suggstion --- collects/2htdp/batch-io.ss | 38 +++++++++---------- .../2htdp/scribblings/batch-io.scrbl | 32 ++++++++-------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/collects/2htdp/batch-io.ss b/collects/2htdp/batch-io.ss index 1e5f65cfcc..33ade31cbf 100644 --- a/collects/2htdp/batch-io.ss +++ b/collects/2htdp/batch-io.ss @@ -13,23 +13,23 @@ read-file ;; String -> String ;; read the specified file as a string - read-as-1strings ;; String -> [Listof 1String] + read-1strings ;; String -> [Listof 1String] ;; read the specified file as a list of 1strings (characters) - read-as-lines ;; String -> [Listof String] + read-lines ;; String -> [Listof String] ;; read the specified file as a list of strings, one per line - read-as-words ;; String -> [Listof String] + read-words ;; String -> [Listof String] ;; read the specified file as a list of white-space separated tokens - read-as-words/line ;; String -> [Listof [Listof String]] + read-words/line ;; String -> [Listof [Listof String]] ;; read the specified file as a list of lines, each line as a list of words - read-as-csv ;; String -> [Listof [Listof (U Any)]] + read-csv-file ;; String -> [Listof [Listof (U Any)]] ;; -- f must be formated as a a file with comma-separated values (Any) ;; read the specified file as a list of lists---one per line---of values (Any) - read-as-csv/rows ;; String ([Listof Any] -> X) -> [Listof X] + read-csv-file/rows ;; String ([Listof Any] -> X) -> [Listof X] ;; -- f must be formated as a a file with comma-separated values (Any) ;; read the specified file as a file of comma-separated values, apply the second ;; argument to each row, i.e., list of CSV on one line @@ -54,33 +54,33 @@ (def-reader (read-file f) (list->string (read-chunks f read-char drop-last-newline))) -(def-reader (read-as-1strings f) +(def-reader (read-1strings f) (map string (read-chunks f read-char drop-last-newline))) -(def-reader (read-as-lines f) +(def-reader (read-lines f) (read-chunks f read-line reverse)) -(def-reader (read-as-words f) - (read-as-words/line/internal f append)) +(def-reader (read-words f) + (read-words/line/internal f append)) -(def-reader (read-as-words/line f) +(def-reader (read-words/line f) ;; String -> [Listof [Listof String]] ;; read the specified file as a list of lines, each line as a list of words - (read-as-words/line/internal f cons)) + (read-words/line/internal f cons)) -(define (read-as-words/line/internal f combine) +(define (read-words/line/internal f combine) (define lines (read-chunks f read-line (lambda (x) x))) (foldl (lambda (f r) (define fst (filter (compose not (curry string=? "")) (split f))) (if (empty? fst) r (combine fst r))) '() lines)) -(def-reader (read-as-csv f) - (read-as-csv/func f)) +(def-reader (read-csv-file f) + (read-csv-file/func f)) -(def-reader (read-as-csv/rows f row) - (check-proc 'read-as-cvs row 1 "one argument" "row") - (read-as-csv/func f row)) +(def-reader (read-csv-file/rows f row) + (check-proc 'read-csv-file row 1 "one argument" "row") + (read-csv-file/func f row)) ;; ----------------------------------------------------------------------------- ;; writer @@ -98,7 +98,7 @@ ;; auxiliaries ;; String [([Listof X] -> Y)] -> [Listof Y] -(define (read-as-csv/func f [row (lambda (x) x)]) +(define (read-csv-file/func f [row (lambda (x) x)]) (local ((define (reader o) (make-csv-reader o '((strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t))))) diff --git a/collects/teachpack/2htdp/scribblings/batch-io.scrbl b/collects/teachpack/2htdp/scribblings/batch-io.scrbl index 11ecdda6b4..cd33ba5996 100644 --- a/collects/teachpack/2htdp/scribblings/batch-io.scrbl +++ b/collects/teachpack/2htdp/scribblings/batch-io.scrbl @@ -56,45 +56,45 @@ assuming the file named @scheme["data.txt"] has this shape: Note how the leading space in the second line translates into the space between the newline indicator and the word @scheme["good"] in the result.} -@item{@reading[read-as-1strings (listof 1string?)]{a list of one-char strings, one per character} +@item{@reading[read-1strings (listof 1string?)]{a list of one-char strings, one per character} @examples[#:eval (examples-batch-io) -(read-as-1strings "data.txt") +(read-1strings "data.txt") ] Note how this function reproduces all parts of the file faithfully, including spaces and newlines.} -@item{@reading[read-as-lines (listof string?)]{a list of strings, one per line} +@item{@reading[read-lines (listof string?)]{a list of strings, one per line} @examples[#:eval (examples-batch-io) -(read-as-lines "data.txt") +(read-lines "data.txt") ] when @scheme["data.txt"] is the name of the same file as in the preceding item. And again, the leading space of the second line shows up in the second string in the list.} -@item{@reading[read-as-words (listof string?)]{a list of strings, one per white-space separated token in the file} +@item{@reading[read-words (listof string?)]{a list of strings, one per white-space separated token in the file} @examples[#:eval (examples-batch-io) -(read-as-words "data.txt") +(read-words "data.txt") ] This time, however, the extra leading space of the second line of @scheme["data.txt"] has disappeared in the result. The space is considered a part of the separator that surrounds the word @scheme["good"]. } -@item{@reading[read-as-words/line (listof string?)]{a list of lists, one per line; each line is represented as a list of white-space separated tokens} +@item{@reading[read-words/line (listof string?)]{a list of lists, one per line; each line is represented as a list of white-space separated tokens} @examples[#:eval (examples-batch-io) -(read-as-words/line "data.txt") +(read-words/line "data.txt") ] -The results is similar to the one that @scheme[read-as-words] produces, +The results is similar to the one that @scheme[read-words] produces, except that the organization of the file into lines is preserved. } -@item{@reading[read-as-csv (listof (listof any/c))]{a list of lists of comma-separated values} +@item{@reading[read-csv-file (listof (listof any/c))]{a list of lists of comma-separated values} @examples[#:eval (examples-batch-io) -(read-as-csv "data.csv") +(read-csv-file "data.csv") ] where the file named @scheme["data.csv"] has this shape: @(file-is "data.csv") @@ -103,16 +103,16 @@ length. Here the third line of the file turns into a row of three elements. } -@item{@defproc[(@read-as-csv/rows [f (and/c string? exists?)][s +@item{@defproc[(@read-csv-file/rows [f (and/c string? exists?)][s (-> (listof any/c) X?)]) (listof X?)]{reads the content of file @scheme[f] and produces it as list of rows, each constructed via @scheme[s]} @examples[#:eval (examples-batch-io) -(read-as-csv/rows "data.csv" (lambda (x) x)) -(read-as-csv/rows "data.csv" length) +(read-csv-file/rows "data.csv" (lambda (x) x)) +(read-csv-file/rows "data.csv" length) ] - The first example shows how @scheme[read-as-csv] is just a short form - for @scheme[read-as-csv/rows]; the second one simply counts the + The first example shows how @scheme[read-csv-file] is just a short form + for @scheme[read-csv-file/rows]; the second one simply counts the number of separated tokens and the result is just a list of numbers. In many cases, the function argument is used to construct a structure from a row.} From 96a3f47ea09e9e8beb11fbf26ba3138a6a289a4f Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Tue, 27 Apr 2010 08:48:07 -0600 Subject: [PATCH 2/2] Fixing cookie regex --- collects/net/cookie-unit.ss | 2 +- collects/tests/net/cookie.ss | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/collects/net/cookie-unit.ss b/collects/net/cookie-unit.ss index 64ff59509b..dd3342410c 100644 --- a/collects/net/cookie-unit.ss +++ b/collects/net/cookie-unit.ss @@ -255,7 +255,7 @@ ;; appear as a block to be legal, and " may only appear as \" (define (rfc2068:quoted-string? s) (and (regexp-match? - #rx"^\"([^\"#\u0000-#\u001F]| |#\return#\newline|#\tab|\\\\\")*\"$" + #rx"^\"([^\"\u0000-\u001F]| |\r\n|\t|\\\\\")*\"$" s) s)) diff --git a/collects/tests/net/cookie.ss b/collects/tests/net/cookie.ss index 601eb3d71f..57200a5927 100644 --- a/collects/tests/net/cookie.ss +++ b/collects/tests/net/cookie.ss @@ -19,12 +19,12 @@ (syntax-rules () [(o/* x) x] [(o/* x f g ...) (f (o/* x g ...))])) - + (define (tests) - + ;; test the most basic functionality (cookie-test (λ (x) x) "a=b; Version=1") - + ;; test each modifier individually (cookie-test (RC cookie:add-comment "set+a+to+b") "a=b; Comment=set+a+to+b; Version=1") @@ -54,7 +54,7 @@ "a=b; Version=1") (cookie-test (RC cookie:version 12) "a=b; Version=12") - + ;; test combinations (cookie-test (o (RC cookie:add-comment "set+a+to+b") (RC cookie:add-domain ".example.net")) @@ -66,7 +66,7 @@ (RC cookie:version 10) (RC cookie:add-max-age 20)) "a=b; Max-Age=20; Path=\"/whatever/wherever/\"; Version=10") - + ;; test error cases (let () (define-syntax cookie-error-test @@ -78,7 +78,18 @@ (cookie-error-test (RC cookie:add-domain "doesntstartwithadot.example.com")) (cookie-error-test (RC cookie:add-domain "bad domain.com")) (cookie-error-test (RC cookie:add-domain ".bad-domain;com"))) - + + ; cookie value + (test + (cookie-value? "value") + (cookie-value? "(") + (cookie-value? "!") + (cookie-value? ")") + (cookie-value? ")!") + (cookie-value? "(!") + (cookie-value? "(!)") + (cookie-value? "!)")) + ) - + (test do (tests)))