diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-09-06 18:12:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-06 18:12:46 +0000 |
commit | aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13 (patch) | |
tree | 7e63b06d1eec92beec6997c9d3ab47a5d6a835be /libgo/go/bufio/example_test.go | |
parent | 920ea3b8ba3164b61ac9490dfdfceb6936eda6dd (diff) | |
download | gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.zip gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.gz gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.bz2 |
libgo: update to Go 1.13beta1 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/193497
From-SVN: r275473
Diffstat (limited to 'libgo/go/bufio/example_test.go')
-rw-r--r-- | libgo/go/bufio/example_test.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libgo/go/bufio/example_test.go b/libgo/go/bufio/example_test.go index 4666e6d..8885d40 100644 --- a/libgo/go/bufio/example_test.go +++ b/libgo/go/bufio/example_test.go @@ -31,6 +31,19 @@ func ExampleScanner_lines() { } } +// Return the most recent call to Scan as a []byte. +func ExampleScanner_Bytes() { + scanner := bufio.NewScanner(strings.NewReader("gopher")) + for scanner.Scan() { + fmt.Println(len(scanner.Bytes()) == 6) + } + if err := scanner.Err(); err != nil { + fmt.Fprintln(os.Stderr, "shouldn't see an error scanning a string") + } + // Output: + // true +} + // Use a Scanner to implement a simple word-count utility by scanning the // input as a sequence of space-delimited tokens. func ExampleScanner_words() { @@ -94,6 +107,9 @@ func ExampleScanner_emptyFinalToken() { return i + 1, data[:i], nil } } + if !atEOF { + return 0, nil, nil + } // There is one final token to be delivered, which may be the empty string. // Returning bufio.ErrFinalToken here tells Scan there are no more tokens after this // but does not trigger an error to be returned from Scan itself. |