]> Cypherpunks repositories - gostls13.git/commitdiff
bytes: add example for (*Buffer).Next
authorjiahua wang <wjh180909@gmail.com>
Fri, 24 Sep 2021 02:07:44 +0000 (10:07 +0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 27 Sep 2021 16:30:23 +0000 (16:30 +0000)
Change-Id: Ic0a97fd7bb89865448e436e5c092415a29d8badf
Reviewed-on: https://go-review.googlesource.com/c/go/+/352009
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: David Chase <drchase@google.com>

src/bytes/example_test.go

index ae93202b5706e12da11cb8866af8f6a9d75b5745..d0d4dd2c2d43b9f3a47e2292dd296b22c266787c 100644 (file)
@@ -54,6 +54,19 @@ func ExampleBuffer_Len() {
        // Output: 5
 }
 
+func ExampleBuffer_Next() {
+       var b bytes.Buffer
+       b.Grow(64)
+       b.Write([]byte("abcde"))
+       fmt.Printf("%s\n", string(b.Next(2)))
+       fmt.Printf("%s\n", string(b.Next(2)))
+       fmt.Printf("%s", string(b.Next(2)))
+       // Output:
+       // ab
+       // cd
+       // e
+}
+
 func ExampleCompare() {
        // Interpret Compare's result by comparing it to zero.
        var a, b []byte