forked from huandu/go-sqlbuilder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstringbuilder.go
51 lines (39 loc) · 1.01 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
// 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) 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()
}