-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathstringbuilder.go
66 lines (53 loc) · 1.31 KB
/
stringbuilder.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
package dry
import (
"bytes"
"fmt"
"io"
"strconv"
)
type StringBuilder struct {
buffer bytes.Buffer
}
func (s *StringBuilder) Write(strings ...string) *StringBuilder {
for _, str := range strings {
s.buffer.WriteString(str)
}
return s
}
func (s *StringBuilder) Printf(format string, args ...interface{}) *StringBuilder {
fmt.Fprintf(&s.buffer, format, args...)
return s
}
func (s *StringBuilder) Byte(value byte) *StringBuilder {
s.buffer.WriteByte(value)
return s
}
func (s *StringBuilder) WriteBytes(bytes []byte) *StringBuilder {
s.buffer.Write(bytes)
return s
}
func (s *StringBuilder) Int(value int) *StringBuilder {
s.buffer.WriteString(strconv.Itoa(value))
return s
}
func (s *StringBuilder) Uint(value uint) *StringBuilder {
s.buffer.WriteString(strconv.FormatUint(uint64(value), 10))
return s
}
func (s *StringBuilder) Float(value float64) *StringBuilder {
s.buffer.WriteString(strconv.FormatFloat(value, 'f', -1, 64))
return s
}
func (s *StringBuilder) Bool(value bool) *StringBuilder {
s.buffer.WriteString(strconv.FormatBool(value))
return s
}
func (s *StringBuilder) WriteTo(writer io.Writer) (n int64, err error) {
return s.buffer.WriteTo(writer)
}
func (s *StringBuilder) Bytes() []byte {
return s.buffer.Bytes()
}
func (s *StringBuilder) String() string {
return s.buffer.String()
}