diff options
author | guitarbum722 <johnkenneth.moore@gmail.com> | 2017-07-26 20:26:18 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2019-06-21 05:21:30 +0000 |
commit | 44c9354c5a780746b4ebef8ce436a10ee37e01cc (patch) | |
tree | 774cca998bc299162bf3fd9a1188037e78daf215 /src/bufio | |
parent | 1130cc745d45bc7248a2e133a609732a14486f01 (diff) | |
download | go-git-44c9354c5a780746b4ebef8ce436a10ee37e01cc.tar.gz |
bufio: add example for Scanner.Bytes
Change-Id: I4a5c7573e13dd85531ee9f4dd2a0d1981bf8cdfa
Reviewed-on: https://go-review.googlesource.com/c/go/+/51412
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/bufio')
-rw-r--r-- | src/bufio/example_test.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/bufio/example_test.go b/src/bufio/example_test.go index bb57139918..e220e0768f 100644 --- a/src/bufio/example_test.go +++ b/src/bufio/example_test.go @@ -31,6 +31,16 @@ func ExampleScanner_lines() { } } +// Use 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) + } + // 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() { |