-
Notifications
You must be signed in to change notification settings - Fork 0
/
buf.go
40 lines (31 loc) · 885 Bytes
/
buf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ustr
import (
"fmt"
"github.com/go-leap/std"
)
// type Writer interface {
// WriteRune(rune) (int, error)
// WriteString(string) (int, error)
// }
// Buf used to wrap `bytes.Buffer`, now wraps `ustd.BytesWriter`.
type Buf struct {
ustd.BytesWriter
}
// Write is equivalent to / short-hand for `me.BytesWriter.WriteString(s)`.
func (me *Buf) Write(s string) {
me.WriteString(s)
}
// Writef uses `fmt.Sprintf`.
func (me *Buf) Writef(s string, args ...interface{}) {
me.WriteString(fmt.Sprintf(s, args...))
}
// Writeln appends `\n` to `s` then writes.
func (me *Buf) Writeln(s string) {
me.WriteString(s + "\n")
}
// Writelnf uses `fmt.Sprintf`.
func (me *Buf) Writelnf(s string, args ...interface{}) {
me.WriteString(fmt.Sprintf(s, args...) + "\n")
}
// String returns `me.Data` converted to `string`.
func (me *Buf) String() string { return string(me.Data) }