Skip to content

Commit

Permalink
Add Buffer.TrimNewline
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua T Corbin committed Jun 18, 2018
1 parent ea5063e commit 7e6877f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7e6877f

Please sign in to comment.