-
Notifications
You must be signed in to change notification settings - Fork 5
/
buffer.go
104 lines (82 loc) · 1.61 KB
/
buffer.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package console
import (
"io"
"slices"
"strconv"
"time"
)
type buffer []byte
func (b *buffer) Grow(n int) {
*b = slices.Grow(*b, n)
}
func (b *buffer) Bytes() []byte {
return *b
}
func (b *buffer) String() string {
return string(*b)
}
func (b *buffer) Len() int {
return len(*b)
}
func (b *buffer) Cap() int {
return cap(*b)
}
func (b *buffer) WriteTo(dst io.Writer) (int64, error) {
l := len(*b)
if l == 0 {
return 0, nil
}
n, err := dst.Write(*b)
if err != nil {
return int64(n), err
}
if n < l {
return int64(n), io.ErrShortWrite
}
b.Reset()
return int64(n), nil
}
func (b *buffer) Reset() {
*b = (*b)[:0]
}
func (b *buffer) Clone() buffer {
return append(buffer(nil), *b...)
}
func (b *buffer) Clip() {
*b = slices.Clip(*b)
}
func (b *buffer) copy(src *buffer) {
if src.Len() > 0 {
b.Append(src.Bytes())
}
}
func (b *buffer) Append(data []byte) {
*b = append(*b, data...)
}
func (b *buffer) AppendString(s string) {
*b = append(*b, s...)
}
// func (b *buffer) AppendQuotedString(s string) {
// b.buff = strconv.AppendQuote(b.buff, s)
// }
func (b *buffer) AppendByte(byt byte) {
*b = append(*b, byt)
}
func (b *buffer) AppendTime(t time.Time, format string) {
*b = t.AppendFormat(*b, format)
}
func (b *buffer) AppendInt(i int64) {
*b = strconv.AppendInt(*b, i, 10)
}
func (b *buffer) AppendUint(i uint64) {
*b = strconv.AppendUint(*b, i, 10)
}
func (b *buffer) AppendFloat(i float64) {
*b = strconv.AppendFloat(*b, i, 'g', -1, 64)
}
func (b *buffer) AppendBool(i bool) {
*b = strconv.AppendBool(*b, i)
}
func (b *buffer) AppendDuration(d time.Duration) {
*b = appendDuration(*b, d)
}