forked from huandu/go-sqlbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringbuilder.go
64 lines (49 loc) · 1.2 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
// Copyright 2023 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package sqlbuilder
import (
"io"
"strings"
)
type stringBuilder struct {
builder *strings.Builder
}
var _ io.Writer = new(stringBuilder)
func newStringBuilder() *stringBuilder {
return &stringBuilder{
builder: &strings.Builder{},
}
}
// WriteLeadingString writes s to internal buffer.
// If it's not the first time to write the string, a blank (" ") will be written before s.
func (sb *stringBuilder) WriteLeadingString(s string) {
if sb.builder.Len() > 0 {
sb.builder.WriteString(" ")
}
sb.builder.WriteString(s)
}
func (sb *stringBuilder) WriteString(s string) {
sb.builder.WriteString(s)
}
func (sb *stringBuilder) WriteStrings(ss []string, sep string) {
if len(ss) == 0 {
return
}
sb.WriteString(ss[0])
for _, s := range ss[1:] {
sb.WriteString(sep)
sb.WriteString(s)
}
}
func (sb *stringBuilder) WriteRune(r rune) {
sb.builder.WriteRune(r)
}
func (sb *stringBuilder) Write(data []byte) (int, error) {
return sb.builder.Write(data)
}
func (sb *stringBuilder) String() string {
return sb.builder.String()
}
func (sb *stringBuilder) Reset() {
sb.builder.Reset()
}