diff options
| author | Rob Pike <r@golang.org> | 2013-02-20 12:14:31 -0800 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2013-02-20 12:14:31 -0800 |
| commit | 55ad7b9bfe86c90cff55e0e8926fd8ff6b3b5182 (patch) | |
| tree | e2c5303f4f4f7c47cb498db4d9d07899303768a9 /src/pkg/strings | |
| parent | 75e7308be8dc13e53b4f39aad67f286e79ac5313 (diff) | |
| download | go-55ad7b9bfe86c90cff55e0e8926fd8ff6b3b5182.tar.xz | |
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 #4802.
R=adg, rogpeppe, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/7322088
Diffstat (limited to 'src/pkg/strings')
| -rw-r--r-- | src/pkg/strings/strings.go | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go index 9203fc5140..ccf415e694 100644 --- a/src/pkg/strings/strings.go +++ b/src/pkg/strings/strings.go @@ -305,7 +305,8 @@ func SplitAfter(s, sep string) []string { } // Fields splits the string s around each instance of one or more consecutive white space -// characters, returning an array of substrings of s or an empty list if s contains only white space. +// characters, as defined by unicode.IsSpace, returning an array of substrings of s or an +// empty list if s contains only white space. func Fields(s string) []string { return FieldsFunc(s, unicode.IsSpace) } |
