internal/buffer: add String method
Change-Id: Ic041a15e505df39476fada1079b31ef6d68c13b5
Reviewed-on: https://go-review.googlesource.com/c/exp/+/435380
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
diff --git a/slog/handler.go b/slog/handler.go
index 0cee928..5ab9fbf 100644
--- a/slog/handler.go
+++ b/slog/handler.go
@@ -181,7 +181,7 @@
buf.WriteString(file)
buf.WriteByte(':')
itoa((*[]byte)(buf), line, -1)
- s := string(*buf)
+ s := buf.String()
buf.Free()
replace(String(key, s))
}
diff --git a/slog/internal/buffer/buffer.go b/slog/internal/buffer/buffer.go
index e059383..60e6646 100644
--- a/slog/internal/buffer/buffer.go
+++ b/slog/internal/buffer/buffer.go
@@ -44,3 +44,7 @@
func (b *Buffer) WriteByte(c byte) {
*b = append(*b, c)
}
+
+func (b *Buffer) String() string {
+ return string(*b)
+}
diff --git a/slog/internal/buffer/buffer_test.go b/slog/internal/buffer/buffer_test.go
index 4466140..dc3966d 100644
--- a/slog/internal/buffer/buffer_test.go
+++ b/slog/internal/buffer/buffer_test.go
@@ -12,7 +12,7 @@
b.WriteString("hello")
b.WriteByte(',')
b.Write([]byte(" world"))
- got := string(*b)
+ got := b.String()
want := "hello, world"
if got != want {
t.Errorf("got %q, want %q", got, want)
diff --git a/slog/record_test.go b/slog/record_test.go
index e526d24..afbd142 100644
--- a/slog/record_test.go
+++ b/slog/record_test.go
@@ -132,7 +132,7 @@
buf.WriteString(file)
buf.WriteByte(':')
itoa((*[]byte)(buf), line, -1)
- s := string(*buf)
+ s := buf.String()
buf.Free()
_ = s
}