Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(688)

Issue 7322088: code review 7322088: bufio: new Scanner interface (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years ago by r
Modified:
12 years ago
Reviewers:
adg, rsc, rog
CC:
adg, rog, bradfitz, rsc, golang-dev
Visibility:
Public.

Description

bufio: new Scanner interface Add a new, simple interface for scanning (probably textual) data, based on a new type called Scanner. It does its own internal buffering, so should be plausibly efficient even without injecting a bufio.Reader. The format of the input is defined by a "split function", by default splitting into lines. Other implemented split functions include single bytes, single runes, and space-separated words. Here's the loop to scan stdin as a file of lines: s := bufio.NewScanner(os.Stdin) for s.Scan() { fmt.Printf("%s\n", s.Bytes()) } if s.Err() != nil { log.Fatal(s.Err()) } While we're dealing with spaces, define what space means to strings.Fields. Fixes issue 4802.

Patch Set 1 #

Total comments: 39

Patch Set 2 : diff -r 0adf91947752 https://code.google.com/p/go/ #

Total comments: 12

Patch Set 3 : diff -r 8b51b7f3d2a6 https://code.google.com/p/go #

Total comments: 26

Patch Set 4 : diff -r 8b51b7f3d2a6 https://code.google.com/p/go #

Patch Set 5 : diff -r 8b51b7f3d2a6 https://code.google.com/p/go #

Patch Set 6 : diff -r 8b51b7f3d2a6 https://code.google.com/p/go #

Patch Set 7 : diff -r 9c3930413c1b https://code.google.com/p/go #

Patch Set 8 : diff -r 9c3930413c1b https://code.google.com/p/go #

Patch Set 9 : diff -r 9c3930413c1b https://code.google.com/p/go #

Patch Set 10 : diff -r a81ef8e0cc05 https://code.google.com/p/go #

Patch Set 11 : diff -r abd0feffdac3 https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+738 lines, -2 lines) Patch
M src/pkg/bufio/bufio_test.go View 1 chunk +1 line, -1 line 0 comments Download
A src/pkg/bufio/export_test.go View 1 2 3 4 5 6 7 8 9 10 1 chunk +27 lines, -0 lines 0 comments Download
A src/pkg/bufio/scan.go View 1 2 3 4 5 6 7 8 9 10 1 chunk +338 lines, -0 lines 0 comments Download
A src/pkg/bufio/scan_test.go View 1 2 3 4 5 6 7 8 9 10 1 chunk +370 lines, -0 lines 0 comments Download
M src/pkg/strings/strings.go View 1 2 1 chunk +2 lines, -1 line 0 comments Download

Messages

Total messages: 23
r
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go/
12 years ago (2013-02-17 00:58:41 UTC) #1
adg
https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/scan.go File src/pkg/bufio/scan.go (right): https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/scan.go#newcode23 src/pkg/bufio/scan.go:23: // Scanning stops, unrecoverably, at EOF, the first I/O ...
12 years ago (2013-02-17 01:27:32 UTC) #2
adg
https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/scan.go File src/pkg/bufio/scan.go (right): https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/scan.go#newcode282 src/pkg/bufio/scan.go:282: func isWhiteSpace(r rune) bool { isSpace? https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/scan_test.go File src/pkg/bufio/scan_test.go ...
12 years ago (2013-02-17 01:35:10 UTC) #3
adg
https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/export_test.go File src/pkg/bufio/export_test.go (right): https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/export_test.go#newcode7 src/pkg/bufio/export_test.go:7: // Exported for testing only. Imported? https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/export_test.go#newcode12 src/pkg/bufio/export_test.go:12: func ...
12 years ago (2013-02-17 01:36:37 UTC) #4
r
https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/export_test.go File src/pkg/bufio/export_test.go (right): https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/export_test.go#newcode7 src/pkg/bufio/export_test.go:7: // Exported for testing only. On 2013/02/17 01:36:37, adg ...
12 years ago (2013-02-17 02:23:22 UTC) #5
r
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years ago (2013-02-17 02:23:45 UTC) #6
adg
LGTM https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/scan.go File src/pkg/bufio/scan.go (right): https://codereview.appspot.com/7322088/diff/1/src/pkg/bufio/scan.go#newcode282 src/pkg/bufio/scan.go:282: func isWhiteSpace(r rune) bool { On 2013/02/17 02:23:22, ...
12 years ago (2013-02-18 03:01:45 UTC) #7
rog
LGTM with a few remarks below. https://codereview.appspot.com/7322088/diff/3002/src/pkg/bufio/export_test.go File src/pkg/bufio/export_test.go (right): https://codereview.appspot.com/7322088/diff/3002/src/pkg/bufio/export_test.go#newcode15 src/pkg/bufio/export_test.go:15: } else { ...
12 years ago (2013-02-18 15:04:11 UTC) #8
bradfitz
https://codereview.appspot.com/7322088/diff/3002/src/pkg/bufio/scan.go File src/pkg/bufio/scan.go (right): https://codereview.appspot.com/7322088/diff/3002/src/pkg/bufio/scan.go#newcode201 src/pkg/bufio/scan.go:201: // Bytes is a split function that returns each ...
12 years ago (2013-02-18 20:09:25 UTC) #9
r
https://codereview.appspot.com/7322088/diff/3002/src/pkg/bufio/export_test.go File src/pkg/bufio/export_test.go (right): https://codereview.appspot.com/7322088/diff/3002/src/pkg/bufio/export_test.go#newcode15 src/pkg/bufio/export_test.go:15: } else { On 2013/02/18 15:04:11, rog wrote: > ...
12 years ago (2013-02-19 17:33:05 UTC) #10
r
Hello golang-dev@googlegroups.com, adg@golang.org, rogpeppe@gmail.com, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years ago (2013-02-19 17:33:19 UTC) #11
rsc
I think your recent update came in while I was looking at this older copy. ...
12 years ago (2013-02-19 17:53:44 UTC) #12
rsc
Actually, looks like I did comment on the right (latest) version.
12 years ago (2013-02-19 17:54:22 UTC) #13
r
https://codereview.appspot.com/7322088/diff/3003/src/pkg/bufio/export_test.go File src/pkg/bufio/export_test.go (right): https://codereview.appspot.com/7322088/diff/3003/src/pkg/bufio/export_test.go#newcode22 src/pkg/bufio/export_test.go:22: func IsSpace(r rune) bool { done, but seems tricky ...
12 years ago (2013-02-19 18:14:36 UTC) #14
r
Hello golang-dev@googlegroups.com, adg@golang.org, rogpeppe@gmail.com, bradfitz@golang.org, rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years ago (2013-02-19 18:14:49 UTC) #15
rog
https://codereview.appspot.com/7322088/diff/3002/src/pkg/bufio/scan.go File src/pkg/bufio/scan.go (right): https://codereview.appspot.com/7322088/diff/3002/src/pkg/bufio/scan.go#newcode266 src/pkg/bufio/scan.go:266: for i, c := range data { On 2013/02/19 ...
12 years ago (2013-02-19 18:18:40 UTC) #16
r
Again, and strongly, this is supposed to be convenient for workaday jobs. You are pushing ...
12 years ago (2013-02-19 18:21:20 UTC) #17
rsc
https://codereview.appspot.com/7322088/diff/3003/src/pkg/bufio/scan.go File src/pkg/bufio/scan.go (right): https://codereview.appspot.com/7322088/diff/3003/src/pkg/bufio/scan.go#newcode30 src/pkg/bufio/scan.go:30: // A typical scan loop over text lines looks ...
12 years ago (2013-02-19 18:23:33 UTC) #18
r
now i'm leaning towards putting an error in. it's trivial to handle in Scan and ...
12 years ago (2013-02-19 18:27:36 UTC) #19
rsc
I don't have a strong opinion on whether SplitFunc returns an error or doesn't. I ...
12 years ago (2013-02-19 18:30:12 UTC) #20
r
Hello adg@golang.org, rogpeppe@gmail.com, bradfitz@golang.org, rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years ago (2013-02-19 22:49:32 UTC) #21
rsc
LGTM
12 years ago (2013-02-20 18:33:47 UTC) #22
r
12 years ago (2013-02-20 20:14:37 UTC) #23
*** Submitted as https://code.google.com/p/go/source/detail?r=f685026a2d38 ***

bufio: new Scanner interface

Add a new, simple interface for scanning (probably textual) data,
based on a new type called Scanner. It does its own internal buffering,
so should be plausibly efficient even without injecting a bufio.Reader.
The format of the input is defined by a "split function", by default
splitting into lines. Other implemented split functions include single
bytes, single runes, and space-separated words.

Here's the loop to scan stdin as a file of lines:

        s := bufio.NewScanner(os.Stdin)
        for s.Scan() {
                fmt.Printf("%s\n", s.Bytes())
        }
        if s.Err() != nil {
                log.Fatal(s.Err())
        }

While we're dealing with spaces, define what space means to strings.Fields.

Fixes issue 4802.

R=adg, rogpeppe, bradfitz, rsc
CC=golang-dev
https://codereview.appspot.com/7322088
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b