Commit 50a1d89a authored by Russ Cox's avatar Russ Cox

fmt: rename buffer.WriteByte to writeByte

Renaming the method makes clear, both to readers and to vet,
that this method is not the implementation of io.ByteWriter.

Working toward making the tree vet-safe instead of having
so many exceptions in cmd/vet/all/whitelist.

For #31916.

Change-Id: I79da062ca6469b62a6b9e284c6cf2413c7425249
Reviewed-on: https://go-review.googlesource.com/c/go/+/176109
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: default avatarAustin Clements <austin@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent a44c3edb
......@@ -23,9 +23,8 @@ cmd/compile/internal/gc/testdata/short_test.go: unreachable code
// These cases are basically ok.
// Errors are handled reasonably and there's no clear need for interface satisfaction.
// Except for the runtime/pprof case, the API is not exported.
fmt/print.go: method WriteByte(c byte) should have signature WriteByte(byte) error
// Also non-standard, but this method is on an unexported type, so it's
// Also on-standard, but this method is on an unexported type, so it's
// irrelevant.
encoding/gob/encode.go: method WriteByte(c byte) should have signature WriteByte(byte) error
......
......@@ -156,10 +156,10 @@ loop:
break
}
if w.fmt.needColon || !p.fmt.plusV {
w.buf.WriteByte(':')
w.buf.writeByte(':')
w.fmt.needColon = false
}
w.buf.WriteString(sep)
w.buf.writeString(sep)
w.fmt.inDetail = false
w.fmt.needNewline = false
}
......@@ -195,24 +195,24 @@ func (p *errPPState) Write(b []byte) (n int, err error) {
for i, c := range b {
if p.fmt.needNewline {
if p.fmt.inDetail && p.fmt.needColon {
p.buf.WriteByte(':')
p.buf.writeByte(':')
p.fmt.needColon = false
}
p.buf.Write(detailSep)
p.buf.write(detailSep)
p.fmt.needNewline = false
}
if c == '\n' {
p.buf.Write(b[k:i])
p.buf.write(b[k:i])
k = i + 1
p.fmt.needNewline = true
}
}
p.buf.Write(b[k:])
p.buf.write(b[k:])
if !p.fmt.inDetail {
p.fmt.needColon = true
}
} else if !p.fmt.inDetail {
p.buf.Write(b)
p.buf.write(b)
}
return len(b), nil
......
......@@ -94,17 +94,17 @@ func (f *fmt) writePadding(n int) {
// pad appends b to f.buf, padded on left (!f.minus) or right (f.minus).
func (f *fmt) pad(b []byte) {
if !f.widPresent || f.wid == 0 {
f.buf.Write(b)
f.buf.write(b)
return
}
width := f.wid - utf8.RuneCount(b)
if !f.minus {
// left padding
f.writePadding(width)
f.buf.Write(b)
f.buf.write(b)
} else {
// right padding
f.buf.Write(b)
f.buf.write(b)
f.writePadding(width)
}
}
......@@ -112,17 +112,17 @@ func (f *fmt) pad(b []byte) {
// padString appends s to f.buf, padded on left (!f.minus) or right (f.minus).
func (f *fmt) padString(s string) {
if !f.widPresent || f.wid == 0 {
f.buf.WriteString(s)
f.buf.writeString(s)
return
}
width := f.wid - utf8.RuneCountInString(s)
if !f.minus {
// left padding
f.writePadding(width)
f.buf.WriteString(s)
f.buf.writeString(s)
} else {
// right padding
f.buf.WriteString(s)
f.buf.writeString(s)
f.writePadding(width)
}
}
......@@ -574,9 +574,9 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) {
// If we're zero padding to the left we want the sign before the leading zeros.
// Achieve this by writing the sign out and then padding the unsigned number.
if f.zero && f.widPresent && f.wid > len(num) {
f.buf.WriteByte(num[0])
f.buf.writeByte(num[0])
f.writePadding(f.wid - len(num))
f.buf.Write(num[1:])
f.buf.write(num[1:])
return
}
f.pad(num)
......
This diff is collapsed.
......@@ -457,7 +457,7 @@ func (s *ss) token(skipSpace bool, f func(rune) bool) []byte {
s.UnreadRune()
break
}
s.buf.WriteRune(r)
s.buf.writeRune(r)
}
return s.buf
}
......@@ -483,7 +483,7 @@ func (s *ss) consume(ok string, accept bool) bool {
}
if indexRune(ok, r) >= 0 {
if accept {
s.buf.WriteRune(r)
s.buf.writeRune(r)
}
return true
}
......@@ -850,20 +850,20 @@ func (s *ss) quotedString() string {
if r == quote {
break
}
s.buf.WriteRune(r)
s.buf.writeRune(r)
}
return string(s.buf)
case '"':
// Double-quoted: Include the quotes and let strconv.Unquote do the backslash escapes.
s.buf.WriteByte('"')
s.buf.writeByte('"')
for {
r := s.mustReadRune()
s.buf.WriteRune(r)
s.buf.writeRune(r)
if r == '\\' {
// In a legal backslash escape, no matter how long, only the character
// immediately after the escape can itself be a backslash or quote.
// Thus we only need to protect the first character after the backslash.
s.buf.WriteRune(s.mustReadRune())
s.buf.writeRune(s.mustReadRune())
} else if r == '"' {
break
}
......@@ -922,7 +922,7 @@ func (s *ss) hexString() string {
if !ok {
break
}
s.buf.WriteByte(b)
s.buf.writeByte(b)
}
if len(s.buf) == 0 {
s.errorString("no hex data for %x string")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment