46 lines
731 B
Go
46 lines
731 B
Go
package editor
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// !buffer
|
|
// ----------------------------------------------------------------------------
|
|
|
|
type buffer struct {
|
|
buf *strings.Builder
|
|
}
|
|
|
|
func newBuffer() *buffer {
|
|
var buf strings.Builder
|
|
|
|
b := new(buffer)
|
|
b.buf = &buf
|
|
|
|
return b
|
|
}
|
|
|
|
func (b *buffer) appendRune(r rune) int {
|
|
size, _ := b.buf.WriteRune(r)
|
|
|
|
return size
|
|
}
|
|
|
|
func (b *buffer) append(s string) int {
|
|
size, _ := b.buf.WriteString(s)
|
|
|
|
return size
|
|
}
|
|
|
|
func (b *buffer) appendLn(s string) int {
|
|
str := fmt.Sprintf("%s\r\n", s)
|
|
size, _ := b.buf.WriteString(str)
|
|
|
|
return size
|
|
}
|
|
|
|
func (b *buffer) toString() string {
|
|
return b.buf.String()
|
|
} |