]> Cypherpunks repositories - gostls13.git/commitdiff
bufio: add example for Scanner.Bytes
authorguitarbum722 <johnkenneth.moore@gmail.com>
Thu, 27 Jul 2017 03:26:18 +0000 (20:26 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 21 Jun 2019 05:21:30 +0000 (05:21 +0000)
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>
src/bufio/example_test.go

index bb5713991805dce5aa54ab626075401e8ce69124..e220e0768f1fd2ce569f9e58a376bec0d658ec59 100644 (file)
@@ -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() {