From: jiahua wang Date: Fri, 24 Sep 2021 02:07:44 +0000 (+0800) Subject: bytes: add example for (*Buffer).Next X-Git-Tag: go1.18beta1~1185 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=078247a4075650aa4eaf9b9e7fab3b4b70b27a5f;p=gostls13.git bytes: add example for (*Buffer).Next Change-Id: Ic0a97fd7bb89865448e436e5c092415a29d8badf Reviewed-on: https://go-review.googlesource.com/c/go/+/352009 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: David Chase --- diff --git a/src/bytes/example_test.go b/src/bytes/example_test.go index ae93202b57..d0d4dd2c2d 100644 --- a/src/bytes/example_test.go +++ b/src/bytes/example_test.go @@ -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