From 078247a4075650aa4eaf9b9e7fab3b4b70b27a5f Mon Sep 17 00:00:00 2001 From: jiahua wang Date: Fri, 24 Sep 2021 10:07:44 +0800 Subject: [PATCH] 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 --- src/bytes/example_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 -- 2.50.0