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 ...@@ -23,9 +23,8 @@ cmd/compile/internal/gc/testdata/short_test.go: unreachable code
// These cases are basically ok. // These cases are basically ok.
// Errors are handled reasonably and there's no clear need for interface satisfaction. // Errors are handled reasonably and there's no clear need for interface satisfaction.
// Except for the runtime/pprof case, the API is not exported. // 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. // irrelevant.
encoding/gob/encode.go: method WriteByte(c byte) should have signature WriteByte(byte) error encoding/gob/encode.go: method WriteByte(c byte) should have signature WriteByte(byte) error
......
...@@ -156,10 +156,10 @@ loop: ...@@ -156,10 +156,10 @@ loop:
break break
} }
if w.fmt.needColon || !p.fmt.plusV { if w.fmt.needColon || !p.fmt.plusV {
w.buf.WriteByte(':') w.buf.writeByte(':')
w.fmt.needColon = false w.fmt.needColon = false
} }
w.buf.WriteString(sep) w.buf.writeString(sep)
w.fmt.inDetail = false w.fmt.inDetail = false
w.fmt.needNewline = false w.fmt.needNewline = false
} }
...@@ -195,24 +195,24 @@ func (p *errPPState) Write(b []byte) (n int, err error) { ...@@ -195,24 +195,24 @@ func (p *errPPState) Write(b []byte) (n int, err error) {
for i, c := range b { for i, c := range b {
if p.fmt.needNewline { if p.fmt.needNewline {
if p.fmt.inDetail && p.fmt.needColon { if p.fmt.inDetail && p.fmt.needColon {
p.buf.WriteByte(':') p.buf.writeByte(':')
p.fmt.needColon = false p.fmt.needColon = false
} }
p.buf.Write(detailSep) p.buf.write(detailSep)
p.fmt.needNewline = false p.fmt.needNewline = false
} }
if c == '\n' { if c == '\n' {
p.buf.Write(b[k:i]) p.buf.write(b[k:i])
k = i + 1 k = i + 1
p.fmt.needNewline = true p.fmt.needNewline = true
} }
} }
p.buf.Write(b[k:]) p.buf.write(b[k:])
if !p.fmt.inDetail { if !p.fmt.inDetail {
p.fmt.needColon = true p.fmt.needColon = true
} }
} else if !p.fmt.inDetail { } else if !p.fmt.inDetail {
p.buf.Write(b) p.buf.write(b)
} }
return len(b), nil return len(b), nil
......
...@@ -94,17 +94,17 @@ func (f *fmt) writePadding(n int) { ...@@ -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). // pad appends b to f.buf, padded on left (!f.minus) or right (f.minus).
func (f *fmt) pad(b []byte) { func (f *fmt) pad(b []byte) {
if !f.widPresent || f.wid == 0 { if !f.widPresent || f.wid == 0 {
f.buf.Write(b) f.buf.write(b)
return return
} }
width := f.wid - utf8.RuneCount(b) width := f.wid - utf8.RuneCount(b)
if !f.minus { if !f.minus {
// left padding // left padding
f.writePadding(width) f.writePadding(width)
f.buf.Write(b) f.buf.write(b)
} else { } else {
// right padding // right padding
f.buf.Write(b) f.buf.write(b)
f.writePadding(width) f.writePadding(width)
} }
} }
...@@ -112,17 +112,17 @@ func (f *fmt) pad(b []byte) { ...@@ -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). // padString appends s to f.buf, padded on left (!f.minus) or right (f.minus).
func (f *fmt) padString(s string) { func (f *fmt) padString(s string) {
if !f.widPresent || f.wid == 0 { if !f.widPresent || f.wid == 0 {
f.buf.WriteString(s) f.buf.writeString(s)
return return
} }
width := f.wid - utf8.RuneCountInString(s) width := f.wid - utf8.RuneCountInString(s)
if !f.minus { if !f.minus {
// left padding // left padding
f.writePadding(width) f.writePadding(width)
f.buf.WriteString(s) f.buf.writeString(s)
} else { } else {
// right padding // right padding
f.buf.WriteString(s) f.buf.writeString(s)
f.writePadding(width) f.writePadding(width)
} }
} }
...@@ -574,9 +574,9 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) { ...@@ -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. // 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. // Achieve this by writing the sign out and then padding the unsigned number.
if f.zero && f.widPresent && f.wid > len(num) { 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.writePadding(f.wid - len(num))
f.buf.Write(num[1:]) f.buf.write(num[1:])
return return
} }
f.pad(num) f.pad(num)
......
...@@ -75,19 +75,19 @@ type GoStringer interface { ...@@ -75,19 +75,19 @@ type GoStringer interface {
// Use simple []byte instead of bytes.Buffer to avoid large dependency. // Use simple []byte instead of bytes.Buffer to avoid large dependency.
type buffer []byte type buffer []byte
func (b *buffer) Write(p []byte) { func (b *buffer) write(p []byte) {
*b = append(*b, p...) *b = append(*b, p...)
} }
func (b *buffer) WriteString(s string) { func (b *buffer) writeString(s string) {
*b = append(*b, s...) *b = append(*b, s...)
} }
func (b *buffer) WriteByte(c byte) { func (b *buffer) writeByte(c byte) {
*b = append(*b, c) *b = append(*b, c)
} }
func (bp *buffer) WriteRune(r rune) { func (bp *buffer) writeRune(r rune) {
if r < utf8.RuneSelf { if r < utf8.RuneSelf {
*bp = append(*bp, byte(r)) *bp = append(*bp, byte(r))
return return
...@@ -179,14 +179,14 @@ func (p *pp) Flag(b int) bool { ...@@ -179,14 +179,14 @@ func (p *pp) Flag(b int) bool {
// Implement Write so we can call Fprintf on a pp (through State), for // Implement Write so we can call Fprintf on a pp (through State), for
// recursive use in custom verbs. // recursive use in custom verbs.
func (p *pp) Write(b []byte) (ret int, err error) { func (p *pp) Write(b []byte) (ret int, err error) {
p.buf.Write(b) p.buf.write(b)
return len(b), nil return len(b), nil
} }
// Implement WriteString so that we can call io.WriteString // Implement WriteString so that we can call io.WriteString
// on a pp (through state), for efficiency. // on a pp (through state), for efficiency.
func (p *pp) WriteString(s string) (ret int, err error) { func (p *pp) WriteString(s string) (ret int, err error) {
p.buf.WriteString(s) p.buf.writeString(s)
return len(s), nil return len(s), nil
} }
...@@ -314,32 +314,32 @@ func parsenum(s string, start, end int) (num int, isnum bool, newi int) { ...@@ -314,32 +314,32 @@ func parsenum(s string, start, end int) (num int, isnum bool, newi int) {
func (p *pp) unknownType(v reflect.Value) { func (p *pp) unknownType(v reflect.Value) {
if !v.IsValid() { if !v.IsValid() {
p.buf.WriteString(nilAngleString) p.buf.writeString(nilAngleString)
return return
} }
p.buf.WriteByte('?') p.buf.writeByte('?')
p.buf.WriteString(v.Type().String()) p.buf.writeString(v.Type().String())
p.buf.WriteByte('?') p.buf.writeByte('?')
} }
func (p *pp) badVerb(verb rune) { func (p *pp) badVerb(verb rune) {
p.erroring = true p.erroring = true
p.buf.WriteString(percentBangString) p.buf.writeString(percentBangString)
p.buf.WriteRune(verb) p.buf.writeRune(verb)
p.buf.WriteByte('(') p.buf.writeByte('(')
switch { switch {
case p.arg != nil: case p.arg != nil:
p.buf.WriteString(reflect.TypeOf(p.arg).String()) p.buf.writeString(reflect.TypeOf(p.arg).String())
p.buf.WriteByte('=') p.buf.writeByte('=')
p.printArg(p.arg, 'v') p.printArg(p.arg, 'v')
case p.value.IsValid(): case p.value.IsValid():
p.buf.WriteString(p.value.Type().String()) p.buf.writeString(p.value.Type().String())
p.buf.WriteByte('=') p.buf.writeByte('=')
p.printValue(p.value, 'v', 0) p.printValue(p.value, 'v', 0)
default: default:
p.buf.WriteString(nilAngleString) p.buf.writeString(nilAngleString)
} }
p.buf.WriteByte(')') p.buf.writeByte(')')
p.erroring = false p.erroring = false
} }
...@@ -421,12 +421,12 @@ func (p *pp) fmtComplex(v complex128, size int, verb rune) { ...@@ -421,12 +421,12 @@ func (p *pp) fmtComplex(v complex128, size int, verb rune) {
switch verb { switch verb {
case 'v', 'b', 'g', 'G', 'x', 'X', 'f', 'F', 'e', 'E': case 'v', 'b', 'g', 'G', 'x', 'X', 'f', 'F', 'e', 'E':
oldPlus := p.fmt.plus oldPlus := p.fmt.plus
p.buf.WriteByte('(') p.buf.writeByte('(')
p.fmtFloat(real(v), size/2, verb) p.fmtFloat(real(v), size/2, verb)
// Imaginary part always has a sign. // Imaginary part always has a sign.
p.fmt.plus = true p.fmt.plus = true
p.fmtFloat(imag(v), size/2, verb) p.fmtFloat(imag(v), size/2, verb)
p.buf.WriteString("i)") p.buf.writeString("i)")
p.fmt.plus = oldPlus p.fmt.plus = oldPlus
default: default:
p.badVerb(verb) p.badVerb(verb)
...@@ -458,28 +458,28 @@ func (p *pp) fmtBytes(v []byte, verb rune, typeString string) { ...@@ -458,28 +458,28 @@ func (p *pp) fmtBytes(v []byte, verb rune, typeString string) {
switch verb { switch verb {
case 'v', 'd': case 'v', 'd':
if p.fmt.sharpV { if p.fmt.sharpV {
p.buf.WriteString(typeString) p.buf.writeString(typeString)
if v == nil { if v == nil {
p.buf.WriteString(nilParenString) p.buf.writeString(nilParenString)
return return
} }
p.buf.WriteByte('{') p.buf.writeByte('{')
for i, c := range v { for i, c := range v {
if i > 0 { if i > 0 {
p.buf.WriteString(commaSpaceString) p.buf.writeString(commaSpaceString)
} }
p.fmt0x64(uint64(c), true) p.fmt0x64(uint64(c), true)
} }
p.buf.WriteByte('}') p.buf.writeByte('}')
} else { } else {
p.buf.WriteByte('[') p.buf.writeByte('[')
for i, c := range v { for i, c := range v {
if i > 0 { if i > 0 {
p.buf.WriteByte(' ') p.buf.writeByte(' ')
} }
p.fmt.fmtInteger(uint64(c), 10, unsigned, verb, ldigits) p.fmt.fmtInteger(uint64(c), 10, unsigned, verb, ldigits)
} }
p.buf.WriteByte(']') p.buf.writeByte(']')
} }
case 's': case 's':
p.fmt.fmtBs(v) p.fmt.fmtBs(v)
...@@ -507,15 +507,15 @@ func (p *pp) fmtPointer(value reflect.Value, verb rune) { ...@@ -507,15 +507,15 @@ func (p *pp) fmtPointer(value reflect.Value, verb rune) {
switch verb { switch verb {
case 'v': case 'v':
if p.fmt.sharpV { if p.fmt.sharpV {
p.buf.WriteByte('(') p.buf.writeByte('(')
p.buf.WriteString(value.Type().String()) p.buf.writeString(value.Type().String())
p.buf.WriteString(")(") p.buf.writeString(")(")
if u == 0 { if u == 0 {
p.buf.WriteString(nilString) p.buf.writeString(nilString)
} else { } else {
p.fmt0x64(uint64(u), true) p.fmt0x64(uint64(u), true)
} }
p.buf.WriteByte(')') p.buf.writeByte(')')
} else { } else {
if u == 0 { if u == 0 {
p.fmt.padString(nilAngleString) p.fmt.padString(nilAngleString)
...@@ -538,7 +538,7 @@ func (p *pp) catchPanic(arg interface{}, verb rune, method string) { ...@@ -538,7 +538,7 @@ func (p *pp) catchPanic(arg interface{}, verb rune, method string) {
// Stringer that fails to guard against nil or a nil pointer for a // Stringer that fails to guard against nil or a nil pointer for a
// value receiver, and in either case, "<nil>" is a nice result. // value receiver, and in either case, "<nil>" is a nice result.
if v := reflect.ValueOf(arg); v.Kind() == reflect.Ptr && v.IsNil() { if v := reflect.ValueOf(arg); v.Kind() == reflect.Ptr && v.IsNil() {
p.buf.WriteString(nilAngleString) p.buf.writeString(nilAngleString)
return return
} }
// Otherwise print a concise panic message. Most of the time the panic // Otherwise print a concise panic message. Most of the time the panic
...@@ -552,15 +552,15 @@ func (p *pp) catchPanic(arg interface{}, verb rune, method string) { ...@@ -552,15 +552,15 @@ func (p *pp) catchPanic(arg interface{}, verb rune, method string) {
// For this output we want default behavior. // For this output we want default behavior.
p.fmt.clearflags() p.fmt.clearflags()
p.buf.WriteString(percentBangString) p.buf.writeString(percentBangString)
p.buf.WriteRune(verb) p.buf.writeRune(verb)
p.buf.WriteString(panicString) p.buf.writeString(panicString)
p.buf.WriteString(method) p.buf.writeString(method)
p.buf.WriteString(" method: ") p.buf.writeString(" method: ")
p.panicking = true p.panicking = true
p.printArg(err, 'v') p.printArg(err, 'v')
p.panicking = false p.panicking = false
p.buf.WriteByte(')') p.buf.writeByte(')')
p.fmt.fmtFlags = oldFlags p.fmt.fmtFlags = oldFlags
} }
...@@ -713,11 +713,11 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) { ...@@ -713,11 +713,11 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) {
switch f := value; value.Kind() { switch f := value; value.Kind() {
case reflect.Invalid: case reflect.Invalid:
if depth == 0 { if depth == 0 {
p.buf.WriteString(invReflectString) p.buf.writeString(invReflectString)
} else { } else {
switch verb { switch verb {
case 'v': case 'v':
p.buf.WriteString(nilAngleString) p.buf.writeString(nilAngleString)
default: default:
p.badVerb(verb) p.badVerb(verb)
} }
...@@ -740,63 +740,63 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) { ...@@ -740,63 +740,63 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) {
p.fmtString(f.String(), verb) p.fmtString(f.String(), verb)
case reflect.Map: case reflect.Map:
if p.fmt.sharpV { if p.fmt.sharpV {
p.buf.WriteString(f.Type().String()) p.buf.writeString(f.Type().String())
if f.IsNil() { if f.IsNil() {
p.buf.WriteString(nilParenString) p.buf.writeString(nilParenString)
return return
} }
p.buf.WriteByte('{') p.buf.writeByte('{')
} else { } else {
p.buf.WriteString(mapString) p.buf.writeString(mapString)
} }
sorted := fmtsort.Sort(f) sorted := fmtsort.Sort(f)
for i, key := range sorted.Key { for i, key := range sorted.Key {
if i > 0 { if i > 0 {
if p.fmt.sharpV { if p.fmt.sharpV {
p.buf.WriteString(commaSpaceString) p.buf.writeString(commaSpaceString)
} else { } else {
p.buf.WriteByte(' ') p.buf.writeByte(' ')
} }
} }
p.printValue(key, verb, depth+1) p.printValue(key, verb, depth+1)
p.buf.WriteByte(':') p.buf.writeByte(':')
p.printValue(sorted.Value[i], verb, depth+1) p.printValue(sorted.Value[i], verb, depth+1)
} }
if p.fmt.sharpV { if p.fmt.sharpV {
p.buf.WriteByte('}') p.buf.writeByte('}')
} else { } else {
p.buf.WriteByte(']') p.buf.writeByte(']')
} }
case reflect.Struct: case reflect.Struct:
if p.fmt.sharpV { if p.fmt.sharpV {
p.buf.WriteString(f.Type().String()) p.buf.writeString(f.Type().String())
} }
p.buf.WriteByte('{') p.buf.writeByte('{')
for i := 0; i < f.NumField(); i++ { for i := 0; i < f.NumField(); i++ {
if i > 0 { if i > 0 {
if p.fmt.sharpV { if p.fmt.sharpV {
p.buf.WriteString(commaSpaceString) p.buf.writeString(commaSpaceString)
} else { } else {
p.buf.WriteByte(' ') p.buf.writeByte(' ')
} }
} }
if p.fmt.plusV || p.fmt.sharpV { if p.fmt.plusV || p.fmt.sharpV {
if name := f.Type().Field(i).Name; name != "" { if name := f.Type().Field(i).Name; name != "" {
p.buf.WriteString(name) p.buf.writeString(name)
p.buf.WriteByte(':') p.buf.writeByte(':')
} }
} }
p.printValue(getField(f, i), verb, depth+1) p.printValue(getField(f, i), verb, depth+1)
} }
p.buf.WriteByte('}') p.buf.writeByte('}')
case reflect.Interface: case reflect.Interface:
value := f.Elem() value := f.Elem()
if !value.IsValid() { if !value.IsValid() {
if p.fmt.sharpV { if p.fmt.sharpV {
p.buf.WriteString(f.Type().String()) p.buf.writeString(f.Type().String())
p.buf.WriteString(nilParenString) p.buf.writeString(nilParenString)
} else { } else {
p.buf.WriteString(nilAngleString) p.buf.writeString(nilAngleString)
} }
} else { } else {
p.printValue(value, verb, depth+1) p.printValue(value, verb, depth+1)
...@@ -826,28 +826,28 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) { ...@@ -826,28 +826,28 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) {
} }
} }
if p.fmt.sharpV { if p.fmt.sharpV {
p.buf.WriteString(f.Type().String()) p.buf.writeString(f.Type().String())
if f.Kind() == reflect.Slice && f.IsNil() { if f.Kind() == reflect.Slice && f.IsNil() {
p.buf.WriteString(nilParenString) p.buf.writeString(nilParenString)
return return
} }
p.buf.WriteByte('{') p.buf.writeByte('{')
for i := 0; i < f.Len(); i++ { for i := 0; i < f.Len(); i++ {
if i > 0 { if i > 0 {
p.buf.WriteString(commaSpaceString) p.buf.writeString(commaSpaceString)
} }
p.printValue(f.Index(i), verb, depth+1) p.printValue(f.Index(i), verb, depth+1)
} }
p.buf.WriteByte('}') p.buf.writeByte('}')
} else { } else {
p.buf.WriteByte('[') p.buf.writeByte('[')
for i := 0; i < f.Len(); i++ { for i := 0; i < f.Len(); i++ {
if i > 0 { if i > 0 {
p.buf.WriteByte(' ') p.buf.writeByte(' ')
} }
p.printValue(f.Index(i), verb, depth+1) p.printValue(f.Index(i), verb, depth+1)
} }
p.buf.WriteByte(']') p.buf.writeByte(']')
} }
case reflect.Ptr: case reflect.Ptr:
// pointer to array or slice or struct? ok at top level // pointer to array or slice or struct? ok at top level
...@@ -855,7 +855,7 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) { ...@@ -855,7 +855,7 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) {
if depth == 0 && f.Pointer() != 0 { if depth == 0 && f.Pointer() != 0 {
switch a := f.Elem(); a.Kind() { switch a := f.Elem(); a.Kind() {
case reflect.Array, reflect.Slice, reflect.Struct, reflect.Map: case reflect.Array, reflect.Slice, reflect.Struct, reflect.Map:
p.buf.WriteByte('&') p.buf.writeByte('&')
p.printValue(a, verb, depth+1) p.printValue(a, verb, depth+1)
return return
} }
...@@ -943,15 +943,15 @@ func (p *pp) argNumber(argNum int, format string, i int, numArgs int) (newArgNum ...@@ -943,15 +943,15 @@ func (p *pp) argNumber(argNum int, format string, i int, numArgs int) (newArgNum
} }
func (p *pp) badArgNum(verb rune) { func (p *pp) badArgNum(verb rune) {
p.buf.WriteString(percentBangString) p.buf.writeString(percentBangString)
p.buf.WriteRune(verb) p.buf.writeRune(verb)
p.buf.WriteString(badIndexString) p.buf.writeString(badIndexString)
} }
func (p *pp) missingArg(verb rune) { func (p *pp) missingArg(verb rune) {
p.buf.WriteString(percentBangString) p.buf.writeString(percentBangString)
p.buf.WriteRune(verb) p.buf.writeRune(verb)
p.buf.WriteString(missingString) p.buf.writeString(missingString)
} }
func (p *pp) doPrintf(format string, a []interface{}) { func (p *pp) doPrintf(format string, a []interface{}) {
...@@ -967,7 +967,7 @@ formatLoop: ...@@ -967,7 +967,7 @@ formatLoop:
i++ i++
} }
if i > lasti { if i > lasti {
p.buf.WriteString(format[lasti:i]) p.buf.writeString(format[lasti:i])
} }
if i >= end { if i >= end {
// done processing format string // done processing format string
...@@ -1025,7 +1025,7 @@ formatLoop: ...@@ -1025,7 +1025,7 @@ formatLoop:
p.fmt.wid, p.fmt.widPresent, argNum = intFromArg(a, argNum) p.fmt.wid, p.fmt.widPresent, argNum = intFromArg(a, argNum)
if !p.fmt.widPresent { if !p.fmt.widPresent {
p.buf.WriteString(badWidthString) p.buf.writeString(badWidthString)
} }
// We have a negative width, so take its value and ensure // We have a negative width, so take its value and ensure
...@@ -1059,7 +1059,7 @@ formatLoop: ...@@ -1059,7 +1059,7 @@ formatLoop:
p.fmt.precPresent = false p.fmt.precPresent = false
} }
if !p.fmt.precPresent { if !p.fmt.precPresent {
p.buf.WriteString(badPrecString) p.buf.writeString(badPrecString)
} }
afterIndex = false afterIndex = false
} else { } else {
...@@ -1076,7 +1076,7 @@ formatLoop: ...@@ -1076,7 +1076,7 @@ formatLoop:
} }
if i >= end { if i >= end {
p.buf.WriteString(noVerbString) p.buf.writeString(noVerbString)
break break
} }
...@@ -1088,7 +1088,7 @@ formatLoop: ...@@ -1088,7 +1088,7 @@ formatLoop:
switch { switch {
case verb == '%': // Percent does not absorb operands and ignores f.wid and f.prec. case verb == '%': // Percent does not absorb operands and ignores f.wid and f.prec.
p.buf.WriteByte('%') p.buf.writeByte('%')
case !p.goodArgNum: case !p.goodArgNum:
p.badArgNum(verb) p.badArgNum(verb)
case argNum >= len(a): // No argument left over to print for the current verb. case argNum >= len(a): // No argument left over to print for the current verb.
...@@ -1112,20 +1112,20 @@ formatLoop: ...@@ -1112,20 +1112,20 @@ formatLoop:
// been used and arguably OK if they're not. // been used and arguably OK if they're not.
if !p.reordered && argNum < len(a) { if !p.reordered && argNum < len(a) {
p.fmt.clearflags() p.fmt.clearflags()
p.buf.WriteString(extraString) p.buf.writeString(extraString)
for i, arg := range a[argNum:] { for i, arg := range a[argNum:] {
if i > 0 { if i > 0 {
p.buf.WriteString(commaSpaceString) p.buf.writeString(commaSpaceString)
} }
if arg == nil { if arg == nil {
p.buf.WriteString(nilAngleString) p.buf.writeString(nilAngleString)
} else { } else {
p.buf.WriteString(reflect.TypeOf(arg).String()) p.buf.writeString(reflect.TypeOf(arg).String())
p.buf.WriteByte('=') p.buf.writeByte('=')
p.printArg(arg, 'v') p.printArg(arg, 'v')
} }
} }
p.buf.WriteByte(')') p.buf.writeByte(')')
} }
} }
...@@ -1135,7 +1135,7 @@ func (p *pp) doPrint(a []interface{}) { ...@@ -1135,7 +1135,7 @@ func (p *pp) doPrint(a []interface{}) {
isString := arg != nil && reflect.TypeOf(arg).Kind() == reflect.String isString := arg != nil && reflect.TypeOf(arg).Kind() == reflect.String
// Add a space between two non-string arguments. // Add a space between two non-string arguments.
if argNum > 0 && !isString && !prevString { if argNum > 0 && !isString && !prevString {
p.buf.WriteByte(' ') p.buf.writeByte(' ')
} }
p.printArg(arg, 'v') p.printArg(arg, 'v')
prevString = isString prevString = isString
...@@ -1147,9 +1147,9 @@ func (p *pp) doPrint(a []interface{}) { ...@@ -1147,9 +1147,9 @@ func (p *pp) doPrint(a []interface{}) {
func (p *pp) doPrintln(a []interface{}) { func (p *pp) doPrintln(a []interface{}) {
for argNum, arg := range a { for argNum, arg := range a {
if argNum > 0 { if argNum > 0 {
p.buf.WriteByte(' ') p.buf.writeByte(' ')
} }
p.printArg(arg, 'v') p.printArg(arg, 'v')
} }
p.buf.WriteByte('\n') p.buf.writeByte('\n')
} }
...@@ -457,7 +457,7 @@ func (s *ss) token(skipSpace bool, f func(rune) bool) []byte { ...@@ -457,7 +457,7 @@ func (s *ss) token(skipSpace bool, f func(rune) bool) []byte {
s.UnreadRune() s.UnreadRune()
break break
} }
s.buf.WriteRune(r) s.buf.writeRune(r)
} }
return s.buf return s.buf
} }
...@@ -483,7 +483,7 @@ func (s *ss) consume(ok string, accept bool) bool { ...@@ -483,7 +483,7 @@ func (s *ss) consume(ok string, accept bool) bool {
} }
if indexRune(ok, r) >= 0 { if indexRune(ok, r) >= 0 {
if accept { if accept {
s.buf.WriteRune(r) s.buf.writeRune(r)
} }
return true return true
} }
...@@ -850,20 +850,20 @@ func (s *ss) quotedString() string { ...@@ -850,20 +850,20 @@ func (s *ss) quotedString() string {
if r == quote { if r == quote {
break break
} }
s.buf.WriteRune(r) s.buf.writeRune(r)
} }
return string(s.buf) return string(s.buf)
case '"': case '"':
// Double-quoted: Include the quotes and let strconv.Unquote do the backslash escapes. // Double-quoted: Include the quotes and let strconv.Unquote do the backslash escapes.
s.buf.WriteByte('"') s.buf.writeByte('"')
for { for {
r := s.mustReadRune() r := s.mustReadRune()
s.buf.WriteRune(r) s.buf.writeRune(r)
if r == '\\' { if r == '\\' {
// In a legal backslash escape, no matter how long, only the character // In a legal backslash escape, no matter how long, only the character
// immediately after the escape can itself be a backslash or quote. // immediately after the escape can itself be a backslash or quote.
// Thus we only need to protect the first character after the backslash. // 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 == '"' { } else if r == '"' {
break break
} }
...@@ -922,7 +922,7 @@ func (s *ss) hexString() string { ...@@ -922,7 +922,7 @@ func (s *ss) hexString() string {
if !ok { if !ok {
break break
} }
s.buf.WriteByte(b) s.buf.writeByte(b)
} }
if len(s.buf) == 0 { if len(s.buf) == 0 {
s.errorString("no hex data for %x string") 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