-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_builder.go
48 lines (36 loc) · 1.41 KB
/
string_builder.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
package g
import "strings"
// Builder represents a string builder.
type Builder struct{ builder *strings.Builder }
// NewBuilder creates a new instance of Builder.
func NewBuilder() *Builder { return &Builder{new(strings.Builder)} }
// Write appends a string to the current state of the builder.
func (b *Builder) Write(str String) *Builder {
b.builder.WriteString(str.Std())
return b
}
// WriteBytes appends a byte slice to the current state of the builder.
func (b *Builder) WriteBytes(bs Bytes) *Builder {
b.builder.Write(bs)
return b
}
// WriteByte appends a byte to the current state of the builder.
func (b *Builder) WriteByte(c byte) *Builder {
b.builder.WriteByte(c)
return b
}
// WriteRune appends a rune to the current state of the builder.
func (b *Builder) WriteRune(r rune) *Builder {
b.builder.WriteRune(r)
return b
}
// Grow increases the capacity of the builder by n bytes.
func (b *Builder) Grow(n int) { b.builder.Grow(n) }
// Cap returns the current capacity of the builder.
func (b *Builder) Cap() int { return b.builder.Cap() }
// Len returns the current length of the string in the builder.
func (b *Builder) Len() int { return b.builder.Len() }
// Reset clears the content of the Builder, resetting it to an empty state.
func (b *Builder) Reset() { b.builder.Reset() }
// String returns the content of the builder as a string.
func (b *Builder) String() String { return String(b.builder.String()) }