Skip to content

Commit

Permalink
rfr(package): rename stringBuffer to stringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Petrukhin committed Jun 10, 2020
1 parent 225e7bf commit ac7d5db
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package xstrings
const bufferMaxInitGrowSize = 2048

// Lazy initialize a buffer.
func allocBuffer(orig, cur string) *bufferString {
output := &bufferString{}
func allocBuffer(orig, cur string) *stringBuilder {
output := &stringBuilder{}
maxSize := len(orig) * 4

// Avoid to reserve too much memory at once.
Expand Down
14 changes: 7 additions & 7 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func ToCamelCase(str string) string {
return ""
}

buf := &bufferString{}
buf := &stringBuilder{}
var r0, r1 rune
var size int

Expand Down Expand Up @@ -111,7 +111,7 @@ func camelCaseToLowerCase(str string, connector rune) string {
return ""
}

buf := &bufferString{}
buf := &stringBuilder{}
wt, word, remaining := nextWord(str)

for len(remaining) > 0 {
Expand Down Expand Up @@ -373,7 +373,7 @@ func nextValidRune(str string, prev rune) (r rune, size int) {
return
}

func toLower(buf *bufferString, wt wordType, str string, connector rune) {
func toLower(buf *stringBuilder, wt wordType, str string, connector rune) {
buf.Grow(buf.Len() + len(str))

if wt != upperCaseWord && wt != connectorWord {
Expand All @@ -400,7 +400,7 @@ func SwapCase(str string) string {
var r rune
var size int

buf := &bufferString{}
buf := &stringBuilder{}

for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
Expand Down Expand Up @@ -434,7 +434,7 @@ func FirstRuneToUpper(str string) string {
return str
}

buf := &bufferString{}
buf := &stringBuilder{}
buf.WriteRune(unicode.ToUpper(r))
buf.WriteString(str[size:])
return buf.String()
Expand All @@ -452,7 +452,7 @@ func FirstRuneToLower(str string) string {
return str
}

buf := &bufferString{}
buf := &stringBuilder{}
buf.WriteRune(unicode.ToLower(r))
buf.WriteString(str[size:])
return buf.String()
Expand Down Expand Up @@ -565,7 +565,7 @@ func Successor(str string) string {

// Needs to add one character for carry.
if i < 0 && carry != ' ' {
buf := &bufferString{}
buf := &stringBuilder{}
buf.Grow(l + 4) // Reserve enough space for write.

if lastAlphanumeric != 0 {
Expand Down
10 changes: 5 additions & 5 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ExpandTabs(str string, tabSize int) string {

var r rune
var i, size, column, expand int
var output *bufferString
var output *stringBuilder

orig := str

Expand Down Expand Up @@ -87,7 +87,7 @@ func LeftJustify(str string, length int, pad string) string {
remains := length - l
padLen := Len(pad)

output := &bufferString{}
output := &stringBuilder{}
output.Grow(len(str) + (remains/padLen+1)*len(pad))
output.WriteString(str)
writePadString(output, pad, padLen, remains)
Expand All @@ -113,7 +113,7 @@ func RightJustify(str string, length int, pad string) string {
remains := length - l
padLen := Len(pad)

output := &bufferString{}
output := &stringBuilder{}
output.Grow(len(str) + (remains/padLen+1)*len(pad))
writePadString(output, pad, padLen, remains)
output.WriteString(str)
Expand All @@ -139,15 +139,15 @@ func Center(str string, length int, pad string) string {
remains := length - l
padLen := Len(pad)

output := &bufferString{}
output := &stringBuilder{}
output.Grow(len(str) + (remains/padLen+1)*len(pad))
writePadString(output, pad, padLen, remains/2)
output.WriteString(str)
writePadString(output, pad, padLen, (remains+1)/2)
return output.String()
}

func writePadString(output *bufferString, pad string, padLen, remains int) {
func writePadString(output *stringBuilder, pad string, padLen, remains int) {
var r rune
var size int

Expand Down
4 changes: 2 additions & 2 deletions manipulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func Insert(dst, src string, index int) string {
// Scrub scrubs invalid utf8 bytes with repl string.
// Adjacent invalid bytes are replaced only once.
func Scrub(str, repl string) string {
var buf *bufferString
var buf *stringBuilder
var r rune
var size, pos int
var hasError bool
Expand All @@ -143,7 +143,7 @@ func Scrub(str, repl string) string {
if r == utf8.RuneError {
if !hasError {
if buf == nil {
buf = &bufferString{}
buf = &stringBuilder{}
}

buf.WriteString(origin[:pos])
Expand Down
2 changes: 1 addition & 1 deletion stringbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package xstrings

import "strings"

type bufferString = strings.Builder
type stringBuilder = strings.Builder
2 changes: 1 addition & 1 deletion stringbuilder_go110.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ package xstrings

import "bytes"

type bufferString struct {
type stringBuilder struct {
bytes.Buffer
}
4 changes: 2 additions & 2 deletions translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (tr *Translator) Translate(str string) string {

orig := str

var output *bufferString
var output *stringBuilder

for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
Expand Down Expand Up @@ -499,7 +499,7 @@ func Squeeze(str, pattern string) string {
var size int
var skipSqueeze, matched bool
var tr *Translator
var output *bufferString
var output *stringBuilder

orig := str
last = -1
Expand Down

0 comments on commit ac7d5db

Please sign in to comment.