Minor pickinesses.

This commit is contained in:
Eli Barzilay 2012-10-15 15:03:53 -04:00
parent 7ffe9f2612
commit d67396cbb1

View File

@ -7,11 +7,12 @@
@title[#:tag "stringport"]{String Ports} @title[#:tag "stringport"]{String Ports}
A @deftech{string port} reads or writes from a @tech{byte string}. An A @deftech{string port} reads or writes from a @tech{byte string}. An
input @tech{string port} can be created from either a @tech{byte string} or a input @tech{string port} can be created from either a @tech{byte string}
@tech{string}; in the latter case, the @tech{string} is effectively converted to or a @tech{string}; in the latter case, the @tech{string} is effectively
a @tech{byte string} using @racket[string->bytes/utf-8]. An output @tech{string port} converted to a @tech{byte string} using @racket[string->bytes/utf-8]. An
collects output into a @tech{byte string}, but @racket[get-output-string] output @tech{string port} collects output into a @tech{byte string}, but
conveniently converts the accumulated bytes to a @tech{string}. @racket[get-output-string] conveniently converts the accumulated bytes
to a @tech{string}.
Input and output @tech{string ports} do not need to be explicitly Input and output @tech{string ports} do not need to be explicitly
closed. The @racket[file-position] procedure works for @tech{string closed. The @racket[file-position] procedure works for @tech{string
@ -21,31 +22,30 @@ ports} in position-setting mode.
@defproc[(open-input-bytes [bstr bytes?] [name any/c 'string]) input-port?]{ @defproc[(open-input-bytes [bstr bytes?] [name any/c 'string]) input-port?]{
Creates an input @tech{string port} that reads characters from @racket[bstr] (see Creates an input @tech{string port} that reads characters from
@secref["bytestrings"]). Modifying @racket[bstr] afterward does not @racket[bstr] (see @secref["bytestrings"]). Modifying @racket[bstr]
affect the byte stream produced by the port. The optional afterward does not affect the byte stream produced by the port. The
@racket[name] argument is used as the name for the returned port.} optional @racket[name] argument is used as the name for the returned
port.}
@examples[ @examples[#:eval sp-eval
#:eval sp-eval
(define sp (open-input-bytes #"(apples 42 day)")) (define sp (open-input-bytes #"(apples 42 day)"))
(define sexp1 (read sp)) (define sexp1 (read sp))
(first sexp1) (first sexp1)
(rest sexp1) (rest sexp1)
(define sp (open-input-bytes #"the cow jumped over the moon\nthe little dog\n")) (read-line (open-input-bytes
(read-line sp) #"the cow jumped over the moon\nthe little dog\n"))
] ]
@refalso["strings"]{strings} @refalso["strings"]{strings}
@defproc[(open-input-string [str string?] [name any/c 'string]) input-port?]{ @defproc[(open-input-string [str string?] [name any/c 'string]) input-port?]{
Creates an input @tech{string port} that reads bytes from the UTF-8 encoding (see Creates an input @tech{string port} that reads bytes from the UTF-8
@secref["encodings"]) of @racket[str]. The optional @racket[name] encoding (see @secref["encodings"]) of @racket[str]. The optional
argument is used as the name for the returned port.} @racket[name] argument is used as the name for the returned port.}
@examples[ @examples[#:eval sp-eval
#:eval sp-eval
(define sp (open-input-string "(λ (x) x)")) (define sp (open-input-string "(λ (x) x)"))
(read sp) (read sp)
(define names (open-input-string "Günter Harder\nFrédéric Paulin\n")) (define names (open-input-string "Günter Harder\nFrédéric Paulin\n"))
@ -54,8 +54,8 @@ argument is used as the name for the returned port.}
@defproc[(open-output-bytes [name any/c 'string]) output-port?]{ @defproc[(open-output-bytes [name any/c 'string]) output-port?]{
Creates an output @tech{string port} that accumulates the output into a byte Creates an output @tech{string port} that accumulates the output into a
string. The optional @racket[name] argument is used as the name for byte string. The optional @racket[name] argument is used as the name for
the returned port.} the returned port.}
@examples[ #:eval sp-eval @examples[ #:eval sp-eval
@ -95,13 +95,13 @@ same as @racket[open-output-bytes].}
[end-pos exact-nonnegative-integer? #f]) [end-pos exact-nonnegative-integer? #f])
bytes?]{ bytes?]{
Returns the bytes accumulated in the @tech{string port} @racket[out] so far in a Returns the bytes accumulated in the @tech{string port} @racket[out] so
freshly allocated @tech{byte string} (including any bytes written after the far in a freshly allocated @tech{byte string} (including any bytes
port's current position, if any). The @racket[out] port must be an written after the port's current position, if any). The @racket[out]
output @tech{string port} produced by @racket[open-output-bytes] (or port must be an output @tech{string port} produced by
@racket[open-output-string]) or a structure whose @racket[open-output-bytes] (or @racket[open-output-string]) or a
@racket[prop:output-port] property refers to such an output port structure whose @racket[prop:output-port] property refers to such an
(transitively). output port (transitively).
If @racket[reset?] is true, then all bytes are removed from the port, If @racket[reset?] is true, then all bytes are removed from the port,
and the port's position is reset to @racket[0]; if @racket[reset?] is and the port's position is reset to @racket[0]; if @racket[reset?] is