1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:14:45 -07:00

all: use strings.Builder instead of bytes.Buffer, and rename builder vars

This commit is contained in:
Sasha Melentyev 2022-09-02 10:47:40 +03:00
parent ec2ea40b31
commit 9419583287
3 changed files with 15 additions and 16 deletions

View File

@ -6,8 +6,8 @@
package str
import (
"bytes"
"fmt"
"strings"
"unicode"
"unicode/utf8"
)
@ -49,7 +49,7 @@ func ToFold(s string) string {
return s
Slow:
var buf bytes.Buffer
var b strings.Builder
for _, r := range s {
// SimpleFold(x) cycles to the next equivalent rune > x
// or wraps around to smaller values. Iterate until it wraps,
@ -65,9 +65,9 @@ Slow:
if 'A' <= r && r <= 'Z' {
r += 'a' - 'A'
}
buf.WriteRune(r)
b.WriteRune(r)
}
return buf.String()
return b.String()
}
// FoldDup reports a pair of strings from the list that are

View File

@ -5,7 +5,6 @@
package gccgoimporter
import (
"bytes"
"errors"
"fmt"
"go/constant"
@ -129,16 +128,16 @@ func (p *parser) parseUnquotedString() string {
if p.tok == scanner.EOF {
p.error("unexpected EOF")
}
var buf bytes.Buffer
buf.WriteString(p.scanner.TokenText())
var b strings.Builder
b.WriteString(p.scanner.TokenText())
// This loop needs to examine each character before deciding whether to consume it. If we see a semicolon,
// we need to let it be consumed by p.next().
for ch := p.scanner.Peek(); ch != '\n' && ch != ';' && ch != scanner.EOF && p.scanner.Whitespace&(1<<uint(ch)) == 0; ch = p.scanner.Peek() {
buf.WriteRune(ch)
b.WriteRune(ch)
p.scanner.Next()
}
p.next()
return buf.String()
return b.String()
}
func (p *parser) next() {

View File

@ -829,18 +829,18 @@ func isQtext(r rune) bool {
// quoteString renders a string as an RFC 5322 quoted-string.
func quoteString(s string) string {
var buf strings.Builder
buf.WriteByte('"')
var b strings.Builder
b.WriteByte('"')
for _, r := range s {
if isQtext(r) || isWSP(r) {
buf.WriteRune(r)
b.WriteRune(r)
} else if isVchar(r) {
buf.WriteByte('\\')
buf.WriteRune(r)
b.WriteByte('\\')
b.WriteRune(r)
}
}
buf.WriteByte('"')
return buf.String()
b.WriteByte('"')
return b.String()
}
// isVchar reports whether r is an RFC 5322 VCHAR character.