mirror of
https://github.com/golang/go
synced 2024-11-23 10:10:02 -07:00
fmt: Remove dead code and make comments and variables consistent.
R=minux.ma, dave, rsc CC=golang-dev https://golang.org/cl/7064055
This commit is contained in:
parent
12e7397ebb
commit
3692dfdd0a
@ -96,7 +96,7 @@ type SI struct {
|
|||||||
I interface{}
|
I interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A type with a String method with pointer receiver for testing %p
|
// P is a type with a String method with pointer receiver for testing %p.
|
||||||
type P int
|
type P int
|
||||||
|
|
||||||
var pValue P
|
var pValue P
|
||||||
@ -674,7 +674,8 @@ func TestStructPrinter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check map printing using substrings so we don't depend on the print order.
|
// presentInMap checks map printing using substrings so we don't depend on the
|
||||||
|
// print order.
|
||||||
func presentInMap(s string, a []string, t *testing.T) {
|
func presentInMap(s string, a []string, t *testing.T) {
|
||||||
for i := 0; i < len(a); i++ {
|
for i := 0; i < len(a); i++ {
|
||||||
loc := strings.Index(s, a[i])
|
loc := strings.Index(s, a[i])
|
||||||
@ -715,8 +716,8 @@ func TestEmptyMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that Sprint (and hence Print, Fprint) puts spaces in the right places,
|
// TestBlank checks that Sprint (and hence Print, Fprint) puts spaces in the
|
||||||
// that is, between arg pairs in which neither is a string.
|
// right places, that is, between arg pairs in which neither is a string.
|
||||||
func TestBlank(t *testing.T) {
|
func TestBlank(t *testing.T) {
|
||||||
got := Sprint("<", 1, ">:", 1, 2, 3, "!")
|
got := Sprint("<", 1, ">:", 1, 2, 3, "!")
|
||||||
expect := "<1>:1 2 3!"
|
expect := "<1>:1 2 3!"
|
||||||
@ -725,8 +726,8 @@ func TestBlank(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that Sprintln (and hence Println, Fprintln) puts spaces in the right places,
|
// TestBlankln checks that Sprintln (and hence Println, Fprintln) puts spaces in
|
||||||
// that is, between all arg pairs.
|
// the right places, that is, between all arg pairs.
|
||||||
func TestBlankln(t *testing.T) {
|
func TestBlankln(t *testing.T) {
|
||||||
got := Sprintln("<", 1, ">:", 1, 2, 3, "!")
|
got := Sprintln("<", 1, ">:", 1, 2, 3, "!")
|
||||||
expect := "< 1 >: 1 2 3 !\n"
|
expect := "< 1 >: 1 2 3 !\n"
|
||||||
@ -735,7 +736,7 @@ func TestBlankln(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Formatter with Sprint, Sprintln, Sprintf
|
// TestFormatterPrintln checks Formatter with Sprint, Sprintln, Sprintf.
|
||||||
func TestFormatterPrintln(t *testing.T) {
|
func TestFormatterPrintln(t *testing.T) {
|
||||||
f := F(1)
|
f := F(1)
|
||||||
expect := "<v=F(1)>\n"
|
expect := "<v=F(1)>\n"
|
||||||
@ -784,7 +785,7 @@ func TestWidthAndPrecision(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A type that panics in String.
|
// Panic is a type that panics in String.
|
||||||
type Panic struct {
|
type Panic struct {
|
||||||
message interface{}
|
message interface{}
|
||||||
}
|
}
|
||||||
@ -799,7 +800,7 @@ func (p Panic) String() string {
|
|||||||
panic(p.message)
|
panic(p.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A type that panics in Format.
|
// PanicF is a type that panics in Format.
|
||||||
type PanicF struct {
|
type PanicF struct {
|
||||||
message interface{}
|
message interface{}
|
||||||
}
|
}
|
||||||
@ -837,7 +838,7 @@ func TestPanics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that erroneous String routine doesn't cause fatal recursion.
|
// recurCount tests that erroneous String routine doesn't cause fatal recursion.
|
||||||
var recurCount = 0
|
var recurCount = 0
|
||||||
|
|
||||||
type Recur struct {
|
type Recur struct {
|
||||||
|
@ -72,7 +72,7 @@ func (f *fmt) init(buf *buffer) {
|
|||||||
f.clearflags()
|
f.clearflags()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute left and right padding widths (only one will be non-zero).
|
// computePadding computes left and right padding widths (only one will be non-zero).
|
||||||
func (f *fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth int) {
|
func (f *fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth int) {
|
||||||
left := !f.minus
|
left := !f.minus
|
||||||
w := f.wid
|
w := f.wid
|
||||||
@ -95,7 +95,7 @@ func (f *fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth i
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate n bytes of padding.
|
// writePadding generates n bytes of padding.
|
||||||
func (f *fmt) writePadding(n int, padding []byte) {
|
func (f *fmt) writePadding(n int, padding []byte) {
|
||||||
for n > 0 {
|
for n > 0 {
|
||||||
m := n
|
m := n
|
||||||
@ -107,8 +107,7 @@ func (f *fmt) writePadding(n int, padding []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append b to f.buf, padded on left (w > 0) or right (w < 0 or f.minus)
|
// pad appends b to f.buf, padded on left (w > 0) or right (w < 0 or f.minus).
|
||||||
// clear flags afterwards.
|
|
||||||
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)
|
||||||
@ -124,8 +123,7 @@ func (f *fmt) pad(b []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// append s to buf, padded on left (w > 0) or right (w < 0 or f.minus).
|
// padString appends s to buf, padded on left (w > 0) or right (w < 0 or f.minus).
|
||||||
// clear flags afterwards.
|
|
||||||
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)
|
||||||
@ -141,17 +139,6 @@ func (f *fmt) padString(s string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func putint(buf []byte, base, val uint64, digits string) int {
|
|
||||||
i := len(buf) - 1
|
|
||||||
for val >= base {
|
|
||||||
buf[i] = digits[val%base]
|
|
||||||
i--
|
|
||||||
val /= base
|
|
||||||
}
|
|
||||||
buf[i] = digits[val]
|
|
||||||
return i - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
trueBytes = []byte("true")
|
trueBytes = []byte("true")
|
||||||
falseBytes = []byte("false")
|
falseBytes = []byte("false")
|
||||||
|
@ -26,8 +26,8 @@ var (
|
|||||||
extraBytes = []byte("%!(EXTRA ")
|
extraBytes = []byte("%!(EXTRA ")
|
||||||
irparenBytes = []byte("i)")
|
irparenBytes = []byte("i)")
|
||||||
bytesBytes = []byte("[]byte{")
|
bytesBytes = []byte("[]byte{")
|
||||||
widthBytes = []byte("%!(BADWIDTH)")
|
badWidthBytes = []byte("%!(BADWIDTH)")
|
||||||
precBytes = []byte("%!(BADPREC)")
|
badPrecBytes = []byte("%!(BADPREC)")
|
||||||
noVerbBytes = []byte("%!(NOVERB)")
|
noVerbBytes = []byte("%!(NOVERB)")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ func newCache(f func() interface{}) *cache {
|
|||||||
|
|
||||||
var ppFree = newCache(func() interface{} { return new(pp) })
|
var ppFree = newCache(func() interface{} { return new(pp) })
|
||||||
|
|
||||||
// Allocate a new pp struct or grab a cached one.
|
// newPrinter allocates a new pp struct or grab a cached one.
|
||||||
func newPrinter() *pp {
|
func newPrinter() *pp {
|
||||||
p := ppFree.get().(*pp)
|
p := ppFree.get().(*pp)
|
||||||
p.panicking = false
|
p.panicking = false
|
||||||
@ -162,7 +162,7 @@ func newPrinter() *pp {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save used pp structs in ppFree; avoids an allocation per invocation.
|
// free saves used pp structs in ppFree; avoids an allocation per invocation.
|
||||||
func (p *pp) free() {
|
func (p *pp) free() {
|
||||||
// Don't hold on to pp structs with large buffers.
|
// Don't hold on to pp structs with large buffers.
|
||||||
if cap(p.buf) > 1024 {
|
if cap(p.buf) > 1024 {
|
||||||
@ -299,7 +299,7 @@ func Sprintln(a ...interface{}) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the i'th arg of the struct value.
|
// getField gets the i'th arg of the struct value.
|
||||||
// If the arg itself is an interface, return a value for
|
// If the arg itself is an interface, return a value for
|
||||||
// the thing inside the interface, not the interface itself.
|
// the thing inside the interface, not the interface itself.
|
||||||
func getField(v reflect.Value, i int) reflect.Value {
|
func getField(v reflect.Value, i int) reflect.Value {
|
||||||
@ -1057,7 +1057,7 @@ func (p *pp) doPrintf(format string, a []interface{}) {
|
|||||||
if i < end && format[i] == '*' {
|
if i < end && format[i] == '*' {
|
||||||
p.fmt.wid, p.fmt.widPresent, i, fieldnum = intFromArg(a, end, i, fieldnum)
|
p.fmt.wid, p.fmt.widPresent, i, fieldnum = intFromArg(a, end, i, fieldnum)
|
||||||
if !p.fmt.widPresent {
|
if !p.fmt.widPresent {
|
||||||
p.buf.Write(widthBytes)
|
p.buf.Write(badWidthBytes)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.fmt.wid, p.fmt.widPresent, i = parsenum(format, i, end)
|
p.fmt.wid, p.fmt.widPresent, i = parsenum(format, i, end)
|
||||||
@ -1067,7 +1067,7 @@ func (p *pp) doPrintf(format string, a []interface{}) {
|
|||||||
if format[i+1] == '*' {
|
if format[i+1] == '*' {
|
||||||
p.fmt.prec, p.fmt.precPresent, i, fieldnum = intFromArg(a, end, i+1, fieldnum)
|
p.fmt.prec, p.fmt.precPresent, i, fieldnum = intFromArg(a, end, i+1, fieldnum)
|
||||||
if !p.fmt.precPresent {
|
if !p.fmt.precPresent {
|
||||||
p.buf.Write(precBytes)
|
p.buf.Write(badPrecBytes)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.fmt.prec, p.fmt.precPresent, i = parsenum(format, i+1, end)
|
p.fmt.prec, p.fmt.precPresent, i = parsenum(format, i+1, end)
|
||||||
|
@ -312,8 +312,9 @@ func notSpace(r rune) bool {
|
|||||||
return !isSpace(r)
|
return !isSpace(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// skipSpace provides Scan() methods the ability to skip space and newline characters
|
// SkipSpace provides Scan methods the ability to skip space and newline
|
||||||
// in keeping with the current scanning mode set by format strings and Scan()/Scanln().
|
// characters in keeping with the current scanning mode set by format strings
|
||||||
|
// and Scan/Scanln.
|
||||||
func (s *ss) SkipSpace() {
|
func (s *ss) SkipSpace() {
|
||||||
s.skipSpace(false)
|
s.skipSpace(false)
|
||||||
}
|
}
|
||||||
@ -381,7 +382,7 @@ func (r *readRune) ReadRune() (rr rune, size int, err error) {
|
|||||||
|
|
||||||
var ssFree = newCache(func() interface{} { return new(ss) })
|
var ssFree = newCache(func() interface{} { return new(ss) })
|
||||||
|
|
||||||
// Allocate a new ss struct or grab a cached one.
|
// newScanState allocates a new ss struct or grab a cached one.
|
||||||
func newScanState(r io.Reader, nlIsSpace, nlIsEnd bool) (s *ss, old ssave) {
|
func newScanState(r io.Reader, nlIsSpace, nlIsEnd bool) (s *ss, old ssave) {
|
||||||
// If the reader is a *ss, then we've got a recursive
|
// If the reader is a *ss, then we've got a recursive
|
||||||
// call to Scan, so re-use the scan state.
|
// call to Scan, so re-use the scan state.
|
||||||
@ -413,7 +414,7 @@ func newScanState(r io.Reader, nlIsSpace, nlIsEnd bool) (s *ss, old ssave) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save used ss structs in ssFree; avoid an allocation per invocation.
|
// free saves used ss structs in ssFree; avoid an allocation per invocation.
|
||||||
func (s *ss) free(old ssave) {
|
func (s *ss) free(old ssave) {
|
||||||
// If it was used recursively, just restore the old state.
|
// If it was used recursively, just restore the old state.
|
||||||
if old.validSave {
|
if old.validSave {
|
||||||
|
@ -626,7 +626,7 @@ func TestScanlnWithMiddleNewline(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special Reader that counts reads at end of file.
|
// eofCounter is a special Reader that counts reads at end of file.
|
||||||
type eofCounter struct {
|
type eofCounter struct {
|
||||||
reader *strings.Reader
|
reader *strings.Reader
|
||||||
eofCount int
|
eofCount int
|
||||||
@ -640,8 +640,8 @@ func (ec *eofCounter) Read(b []byte) (n int, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that when we scan, we see at most EOF once per call to a Scan function,
|
// TestEOF verifies that when we scan, we see at most EOF once per call to a
|
||||||
// and then only when it's really an EOF
|
// Scan function, and then only when it's really an EOF.
|
||||||
func TestEOF(t *testing.T) {
|
func TestEOF(t *testing.T) {
|
||||||
ec := &eofCounter{strings.NewReader("123\n"), 0}
|
ec := &eofCounter{strings.NewReader("123\n"), 0}
|
||||||
var a int
|
var a int
|
||||||
@ -668,7 +668,7 @@ func TestEOF(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that we see an EOF error if we run out of input.
|
// TestEOFAtEndOfInput verifies that we see an EOF error if we run out of input.
|
||||||
// This was a buglet: we used to get "expected integer".
|
// This was a buglet: we used to get "expected integer".
|
||||||
func TestEOFAtEndOfInput(t *testing.T) {
|
func TestEOFAtEndOfInput(t *testing.T) {
|
||||||
var i, j int
|
var i, j int
|
||||||
@ -730,7 +730,8 @@ func TestEOFAllTypes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that, at least when using bufio, successive calls to Fscan do not lose runes.
|
// TestUnreadRuneWithBufio verifies that, at least when using bufio, successive
|
||||||
|
// calls to Fscan do not lose runes.
|
||||||
func TestUnreadRuneWithBufio(t *testing.T) {
|
func TestUnreadRuneWithBufio(t *testing.T) {
|
||||||
r := bufio.NewReader(strings.NewReader("123αb"))
|
r := bufio.NewReader(strings.NewReader("123αb"))
|
||||||
var i int
|
var i int
|
||||||
@ -753,7 +754,7 @@ func TestUnreadRuneWithBufio(t *testing.T) {
|
|||||||
|
|
||||||
type TwoLines string
|
type TwoLines string
|
||||||
|
|
||||||
// Attempt to read two lines into the object. Scanln should prevent this
|
// Scan attempts to read two lines into the object. Scanln should prevent this
|
||||||
// because it stops at newline; Scan and Scanf should be fine.
|
// because it stops at newline; Scan and Scanf should be fine.
|
||||||
func (t *TwoLines) Scan(state ScanState, verb rune) error {
|
func (t *TwoLines) Scan(state ScanState, verb rune) error {
|
||||||
chars := make([]rune, 0, 100)
|
chars := make([]rune, 0, 100)
|
||||||
@ -820,7 +821,8 @@ func (s *simpleReader) Read(b []byte) (n int, err error) {
|
|||||||
return s.sr.Read(b)
|
return s.sr.Read(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that Fscanf does not read past newline. Issue 3481.
|
// TestLineByLineFscanf tests that Fscanf does not read past newline. Issue
|
||||||
|
// 3481.
|
||||||
func TestLineByLineFscanf(t *testing.T) {
|
func TestLineByLineFscanf(t *testing.T) {
|
||||||
r := &simpleReader{strings.NewReader("1\n2\n")}
|
r := &simpleReader{strings.NewReader("1\n2\n")}
|
||||||
var i, j int
|
var i, j int
|
||||||
@ -862,7 +864,7 @@ func (r *RecursiveInt) Scan(state ScanState, verb rune) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the same scanning task as RecursiveInt.Scan
|
// scanInts performs the same scanning task as RecursiveInt.Scan
|
||||||
// but without recurring through scanner, so we can compare
|
// but without recurring through scanner, so we can compare
|
||||||
// performance more directly.
|
// performance more directly.
|
||||||
func scanInts(r *RecursiveInt, b *bytes.Buffer) (err error) {
|
func scanInts(r *RecursiveInt, b *bytes.Buffer) (err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user