gilo/internal/buffer/buffer.go

47 lines
739 B
Go
Raw Normal View History

2021-04-02 13:11:54 -04:00
package buffer
import (
"fmt"
"strings"
)
// ----------------------------------------------------------------------------
// !Output Buffer
// ----------------------------------------------------------------------------
2021-04-02 13:11:54 -04:00
type Buffer struct {
buf *strings.Builder
}
2021-04-02 13:11:54 -04:00
func NewBuffer() *Buffer {
var buf strings.Builder
2021-04-02 13:11:54 -04:00
b := new(Buffer)
b.buf = &buf
return b
}
2021-04-02 13:11:54 -04:00
func (b *Buffer) AppendRune(r rune) int {
size, _ := b.buf.WriteRune(r)
return size
}
2021-04-02 13:11:54 -04:00
func (b *Buffer) Append(s string) int {
size, _ := b.buf.WriteString(s)
return size
}
2021-04-02 13:11:54 -04:00
func (b *Buffer) AppendLn(s string) int {
str := fmt.Sprintf("%s\r\n", s)
size, _ := b.buf.WriteString(str)
return size
}
2021-04-02 13:11:54 -04:00
func (b *Buffer) ToString() string {
return b.buf.String()
}