Commit d1d9ad58 authored by Ian Lance Taylor's avatar Ian Lance Taylor

bufio: fix ExampleScanner_Bytes comment, add error check

Followup to CL 51412.

Change-Id: Ic83c833e2c571cd7c8293d998ff745f181037a61
Reviewed-on: https://go-review.googlesource.com/c/go/+/183657
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
parent 5f7e9ced
...@@ -31,12 +31,15 @@ func ExampleScanner_lines() { ...@@ -31,12 +31,15 @@ func ExampleScanner_lines() {
} }
} }
// Use return the most recent call to Scan as a []byte // Return the most recent call to Scan as a []byte.
func ExampleScanner_Bytes() { func ExampleScanner_Bytes() {
scanner := bufio.NewScanner(strings.NewReader("gopher")) scanner := bufio.NewScanner(strings.NewReader("gopher"))
for scanner.Scan() { for scanner.Scan() {
fmt.Println(len(scanner.Bytes()) == 6) 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: // Output:
// true // true
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment