Add `in-bytes-lines'
svn: r17261
This commit is contained in:
parent
d339a01d04
commit
c8c9bd0556
|
@ -35,6 +35,7 @@
|
||||||
(rename *in-input-port-chars in-input-port-chars)
|
(rename *in-input-port-chars in-input-port-chars)
|
||||||
(rename *in-port in-port)
|
(rename *in-port in-port)
|
||||||
(rename *in-lines in-lines)
|
(rename *in-lines in-lines)
|
||||||
|
(rename *in-bytes-lines in-bytes-lines)
|
||||||
in-hash
|
in-hash
|
||||||
in-hash-keys
|
in-hash-keys
|
||||||
in-hash-values
|
in-hash-values
|
||||||
|
@ -489,6 +490,19 @@
|
||||||
"'linefeed, 'return, 'return-linefeed, 'any, or 'any-one"
|
"'linefeed, 'return, 'return-linefeed, 'any, or 'any-one"
|
||||||
mode))
|
mode))
|
||||||
(in-producer (lambda () (read-line p mode)) eof)]))
|
(in-producer (lambda () (read-line p mode)) eof)]))
|
||||||
|
|
||||||
|
(define in-bytes-lines
|
||||||
|
(case-lambda
|
||||||
|
[() (in-bytes-lines (current-input-port) 'any)]
|
||||||
|
[(p) (in-bytes-lines p 'any)]
|
||||||
|
[(p mode)
|
||||||
|
(unless (input-port? p) (raise-type-error 'in-bytes-lines "input-port" p))
|
||||||
|
(unless (memq mode '(linefeed return return-linefeed any any-one))
|
||||||
|
(raise-type-error
|
||||||
|
'in-bytes-lines
|
||||||
|
"'linefeed, 'return, 'return-linefeed, 'any, or 'any-one"
|
||||||
|
mode))
|
||||||
|
(in-producer (lambda () (read-bytes-line p mode)) eof)]))
|
||||||
|
|
||||||
(define (in-hash ht)
|
(define (in-hash ht)
|
||||||
(unless (hash? ht) (raise-type-error 'in-hash "hash" ht))
|
(unless (hash? ht) (raise-type-error 'in-hash "hash" ht))
|
||||||
|
@ -1255,6 +1269,26 @@
|
||||||
mode*))
|
mode*))
|
||||||
(lambda () (read-line p* mode*)))
|
(lambda () (read-line p* mode*)))
|
||||||
eof)]])))
|
eof)]])))
|
||||||
|
|
||||||
|
(define-sequence-syntax *in-bytes-lines
|
||||||
|
(lambda () #'in-bytes-lines)
|
||||||
|
(lambda (stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[[(id) (_)] #'[(id) (*in-bytes-lines (current-input-port) 'any)]]
|
||||||
|
[[(id) (_ p)] #'[(id) (*in-bytes-lines p 'any)]]
|
||||||
|
[[(id) (_ p mode)]
|
||||||
|
#'[(id) (*in-producer
|
||||||
|
(let ([p* p] [mode* mode])
|
||||||
|
(unless (input-port? p*)
|
||||||
|
(raise-type-error 'in-bytes-lines "input-port" p*))
|
||||||
|
(unless (memq mode* '(linefeed return return-linefeed any
|
||||||
|
any-one))
|
||||||
|
(raise-type-error
|
||||||
|
'in-bytes-lines
|
||||||
|
"'linefeed, 'return, 'return-linefeed, 'any, or 'any-one"
|
||||||
|
mode*))
|
||||||
|
(lambda () (read-bytes-line p* mode*)))
|
||||||
|
eof)]])))
|
||||||
|
|
||||||
(define-sequence-syntax *in-input-port-bytes
|
(define-sequence-syntax *in-input-port-bytes
|
||||||
(lambda () #'in-input-port-bytes)
|
(lambda () #'in-input-port-bytes)
|
||||||
|
|
|
@ -167,6 +167,15 @@ Returns a sequence equivalent to @scheme[(in-port (lambda (p)
|
||||||
whereas the default mode of @scheme[read-line] is
|
whereas the default mode of @scheme[read-line] is
|
||||||
@scheme['linefeed]. }
|
@scheme['linefeed]. }
|
||||||
|
|
||||||
|
@defproc[(in-bytes-lines [in input-port? (current-input-port)]
|
||||||
|
[mode (or/c 'linefeed 'return 'return-linefeed 'any 'any-one) 'any])
|
||||||
|
sequence?]{
|
||||||
|
|
||||||
|
Returns a sequence equivalent to @scheme[(in-port (lambda (p)
|
||||||
|
(read-bytes-line p mode)) in)]. Note that the default mode is @scheme['any],
|
||||||
|
whereas the default mode of @scheme[read-bytes-line] is
|
||||||
|
@scheme['linefeed]. }
|
||||||
|
|
||||||
@defproc[(in-hash [hash hash?]) sequence?]{
|
@defproc[(in-hash [hash hash?]) sequence?]{
|
||||||
Returns a sequence equivalent to @scheme[hash].
|
Returns a sequence equivalent to @scheme[hash].
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,9 @@
|
||||||
(test-generator [((123) 4)] (in-port read (open-input-string "(123) 4")))
|
(test-generator [((123) 4)] (in-port read (open-input-string "(123) 4")))
|
||||||
(test-generator [(65 66 67)] (in-port read-byte (open-input-string "ABC")))
|
(test-generator [(65 66 67)] (in-port read-byte (open-input-string "ABC")))
|
||||||
|
|
||||||
|
(test-generator [("abc" "def")] (in-lines (open-input-string "abc\ndef")))
|
||||||
|
(test-generator [(#"abc" #"def")] (in-bytes-lines (open-input-string "abc\ndef")))
|
||||||
|
|
||||||
(test-generator [(0 1 2 3 4 5)] (in-sequences (in-range 6)))
|
(test-generator [(0 1 2 3 4 5)] (in-sequences (in-range 6)))
|
||||||
(test-generator [(0 1 2 3 4 5)] (in-sequences (in-range 4) '(4 5)))
|
(test-generator [(0 1 2 3 4 5)] (in-sequences (in-range 4) '(4 5)))
|
||||||
(test-generator [(0 1 2 3 4 5)] (in-sequences (in-range 6) '()))
|
(test-generator [(0 1 2 3 4 5)] (in-sequences (in-range 6) '()))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user