From 7e6877fe747c2bd12a44a57a6f75c970f3f2f9cd Mon Sep 17 00:00:00 2001 From: Joshua T Corbin Date: Mon, 18 Jun 2018 12:51:14 -0700 Subject: [PATCH] Add Buffer.TrimNewline --- buffer/buffer.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/buffer/buffer.go b/buffer/buffer.go index ba918d78f..a8bc24df4 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -98,6 +98,15 @@ func (b *Buffer) Write(bs []byte) (int, error) { return len(bs), nil } +// TrimNewline trims any final "\n" byte from the end of the buffer. +func (b *Buffer) TrimNewline() { + if i := len(b.bs) - 1; i >= 0 { + if b.bs[i] == '\n' { + b.bs = b.bs[:i] + } + } +} + // Free returns the Buffer to its Pool. // // Callers must not retain references to the Buffer after calling Free.