diff options
| author | Caleb Spare <cespare@gmail.com> | 2017-10-31 16:51:21 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-11-06 18:23:51 +0000 |
| commit | 37b056948d058679efa4e87fb6c9b2a2ddfa31a3 (patch) | |
| tree | ed78c2085005ec9804ada677512d30633182bc63 /src/strings/example_test.go | |
| parent | e49d074c3449736d283354957d7e5f55a465e67b (diff) | |
| download | go-37b056948d058679efa4e87fb6c9b2a2ddfa31a3.tar.xz | |
strings: add Builder
This is like a write-only subset of bytes.Buffer with an
allocation-free String method.
Fixes #18990.
Change-Id: Icdf7240f4309a52924dc3af04a39ecd737a210f4
Reviewed-on: https://go-review.googlesource.com/74931
Run-TryBot: Caleb Spare <cespare@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/strings/example_test.go')
| -rw-r--r-- | src/strings/example_test.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/strings/example_test.go b/src/strings/example_test.go index f7a78b4385..607e4a0a70 100644 --- a/src/strings/example_test.go +++ b/src/strings/example_test.go @@ -351,3 +351,14 @@ func ExampleTrimRightFunc() { })) // Output: ¡¡¡Hello, Gophers } + +func ExampleBuilder() { + var b strings.Builder + for i := 3; i >= 1; i-- { + fmt.Fprintf(&b, "%d...", i) + } + b.WriteString("ignition") + fmt.Println(b.String()) + + // Output: 3...2...1...ignition +} |
