fmt: allow recursive calls to Fscan etc.
Add a new Read method to ScanState so that it
satisfies the io.Reader interface; rename
Getrune and Ungetrune to ReadRune and UnreadRune.
Make sure ReadRune does not read past width restrictions;
remove now-unnecessary Width method from ScanState.
Also make the documentation a little clearer as to
how ReadRune and UnreadRune are used.
PTAL.
i've removed the Width field as it now seems redundant; the Token method could
also go now, as it's now equivalent to Scan(state, &s), but efficiency concerns
might rule this out.
http://codereview.appspot.com/4240056/diff/4002/src/pkg/fmt/doc.go
File src/pkg/fmt/doc.go (right):
http://codereview.appspot.com/4240056/diff/4002/src/pkg/fmt/doc.go#newcode167
src/pkg/fmt/doc.go:167: Note: Fscan etc. can read one character (rune) past the
input
On 2011/03/01 19:27:18, r wrote:
> one space
ah... funnily enough the responsibility for that lies with some other code of
yours, also named fmt.
On Mar 2, 2011, at 6:23 AM, rogpeppe@gmail.com wrote:
> PTAL.
>
> i've removed the Width field as it now seems redundant; the Token method
> could also go now, as it's now equivalent to Scan(state, &s), but
> efficiency concerns might rule this out.
>
>
>
> http://codereview.appspot.com/4240056/diff/4002/src/pkg/fmt/doc.go
> File src/pkg/fmt/doc.go (right):
>
> http://codereview.appspot.com/4240056/diff/4002/src/pkg/fmt/doc.go#newcode167
> src/pkg/fmt/doc.go:167: Note: Fscan etc. can read one character (rune)
> past the input
> On 2011/03/01 19:27:18, r wrote:
>> one space
>
> ah... funnily enough the responsibility for that lies with some other
> code of yours, also named fmt.
my memory may be wrong but i believe td wrote fmt. all i added was retaining
indentation.
-rob
On 2 March 2011 18:07, Rob 'Commander' Pike <r@google.com> wrote:
>
> On Mar 2, 2011, at 6:23 AM, rogpeppe@gmail.com wrote:
>
>> PTAL.
>>
>> i've removed the Width field as it now seems redundant; the Token method
>> could also go now, as it's now equivalent to Scan(state, &s), but
>> efficiency concerns might rule this out.
>>
>>
>>
>> http://codereview.appspot.com/4240056/diff/4002/src/pkg/fmt/doc.go
>> File src/pkg/fmt/doc.go (right):
>>
>> http://codereview.appspot.com/4240056/diff/4002/src/pkg/fmt/doc.go#newcode167
>> src/pkg/fmt/doc.go:167: Note: Fscan etc. can read one character (rune)
>> past the input
>> On 2011/03/01 19:27:18, r wrote:
>>> one space
>>
>> ah... funnily enough the responsibility for that lies with some other
>> code of yours, also named fmt.
>
> my memory may be wrong but i believe td wrote fmt. all i added was retaining
indentation.
ah, i didn't look too closely and presumed you'd rewritten it
when you did that.
And the whole one-space/two-space thing is a minefield anyway. One space should
be necessary but for some reason everyone but me prefers to work in a colored,
fixed-width visual presentation model from the 1960s best suited to airline
reservation systems.
But I digress.
Back to your code.
-rob
the scanner may care anyway and knowing in advance how wide the field is could
be used for buffer management, etc. i suggest leaving it in but saying what you
wrote: you'll get EOF if you read past.
-rob
http://codereview.appspot.com/4240056/diff/16004/src/pkg/fmt/scan.go File src/pkg/fmt/scan.go (right): http://codereview.appspot.com/4240056/diff/16004/src/pkg/fmt/scan.go#newcode42 src/pkg/fmt/scan.go:42: // Because ReadRune is implemented by the interface, Read ...
> the scanner may care anyway and knowing in advance how wide the field is could
be used for buffer management, etc. i suggest leaving it in but saying what you
wrote: you'll get EOF if you read past.
done, but i think the documentation on ReadRune is sufficient in itself without
adding to the Width doc.
http://codereview.appspot.com/4240056/diff/16004/src/pkg/fmt/scan.go
File src/pkg/fmt/scan.go (right):
http://codereview.appspot.com/4240056/diff/16004/src/pkg/fmt/scan.go#newcode42
src/pkg/fmt/scan.go:42: // Because ReadRune is implemented by the interface,
Read will never be
On 2011/03/02 18:35:48, r wrote:
> maybe s/will/should/. it's a specification.
Done.
*** Submitted as http://code.google.com/p/go/source/detail?r=98d584670c65 ***
fmt: allow recursive calls to Fscan etc.
Add a new Read method to ScanState so that it
satisfies the io.Reader interface; rename
Getrune and Ungetrune to ReadRune and UnreadRune.
Make sure ReadRune does not read past width restrictions;
remove now-unnecessary Width method from ScanState.
Also make the documentation a little clearer as to
how ReadRune and UnreadRune are used.
R=r, r2
CC=golang-dev
http://codereview.appspot.com/4240056
Committer: Rob Pike <r@golang.org>
Issue 4240056: code review 4240056: fmt: allow recursive calls to Fscan etc.
(Closed)
Created 14 years ago by rog
Modified 14 years ago
Reviewers:
Base URL:
Comments: 13