Rename pad function to indent.

The name indent better describes the function.  This also will help
differentiate the function from planned functions that are intended to
perform padding for the purposes of aligning fields, types, and values.
This commit is contained in:
Dave Collins 2013-02-03 01:33:35 -06:00
parent e183fe2f19
commit 52f41f689f
2 changed files with 22 additions and 22 deletions

View File

@ -39,7 +39,7 @@ func (s *pstringer) String() string {
} }
// xref1 and xref2 are cross referencing structs for testing circular reference // xref1 and xref2 are cross referencing structs for testing circular reference
// detection. // detection.
type xref1 struct { type xref1 struct {
ps2 *xref2 ps2 *xref2
} }

View File

@ -27,19 +27,19 @@ import (
// dumpState contains information about the state of a dump operation. // dumpState contains information about the state of a dump operation.
type dumpState struct { type dumpState struct {
w io.Writer w io.Writer
depth int depth int
pointers map[uintptr]int pointers map[uintptr]int
ignoreNextType bool ignoreNextType bool
ignoreNextPad bool ignoreNextIndent bool
cs *ConfigState cs *ConfigState
} }
// pad performs indentation according to the depth level and cs.Indent // indent performs indentation according to the depth level and cs.Indent
// option. // option.
func (d *dumpState) pad() { func (d *dumpState) indent() {
if d.ignoreNextPad { if d.ignoreNextIndent {
d.ignoreNextPad = false d.ignoreNextIndent = false
return return
} }
d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth)) d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth))
@ -148,14 +148,14 @@ func (d *dumpState) dump(v reflect.Value) {
// Handle pointers specially. // Handle pointers specially.
if kind == reflect.Ptr { if kind == reflect.Ptr {
d.pad() d.indent()
d.dumpPtr(v) d.dumpPtr(v)
return return
} }
// Print type information unless already handled elsewhere. // Print type information unless already handled elsewhere.
if !d.ignoreNextType { if !d.ignoreNextType {
d.pad() d.indent()
d.w.Write(openParenBytes) d.w.Write(openParenBytes)
d.w.Write([]byte(v.Type().String())) d.w.Write([]byte(v.Type().String()))
d.w.Write(closeParenBytes) d.w.Write(closeParenBytes)
@ -203,7 +203,7 @@ func (d *dumpState) dump(v reflect.Value) {
d.w.Write(openBraceNewlineBytes) d.w.Write(openBraceNewlineBytes)
d.depth++ d.depth++
if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
d.pad() d.indent()
d.w.Write(maxNewlineBytes) d.w.Write(maxNewlineBytes)
} else { } else {
numEntries := v.Len() numEntries := v.Len()
@ -217,7 +217,7 @@ func (d *dumpState) dump(v reflect.Value) {
} }
} }
d.depth-- d.depth--
d.pad() d.indent()
d.w.Write(closeBraceBytes) d.w.Write(closeBraceBytes)
case reflect.String: case reflect.String:
@ -234,7 +234,7 @@ func (d *dumpState) dump(v reflect.Value) {
d.w.Write(openBraceNewlineBytes) d.w.Write(openBraceNewlineBytes)
d.depth++ d.depth++
if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
d.pad() d.indent()
d.w.Write(maxNewlineBytes) d.w.Write(maxNewlineBytes)
} else { } else {
numEntries := v.Len() numEntries := v.Len()
@ -242,7 +242,7 @@ func (d *dumpState) dump(v reflect.Value) {
for i, key := range keys { for i, key := range keys {
d.dump(d.unpackValue(key)) d.dump(d.unpackValue(key))
d.w.Write(colonSpaceBytes) d.w.Write(colonSpaceBytes)
d.ignoreNextPad = true d.ignoreNextIndent = true
d.dump(d.unpackValue(v.MapIndex(key))) d.dump(d.unpackValue(v.MapIndex(key)))
if i < (numEntries - 1) { if i < (numEntries - 1) {
d.w.Write(commaNewlineBytes) d.w.Write(commaNewlineBytes)
@ -252,24 +252,24 @@ func (d *dumpState) dump(v reflect.Value) {
} }
} }
d.depth-- d.depth--
d.pad() d.indent()
d.w.Write(closeBraceBytes) d.w.Write(closeBraceBytes)
case reflect.Struct: case reflect.Struct:
d.w.Write(openBraceNewlineBytes) d.w.Write(openBraceNewlineBytes)
d.depth++ d.depth++
if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
d.pad() d.indent()
d.w.Write(maxNewlineBytes) d.w.Write(maxNewlineBytes)
} else { } else {
vt := v.Type() vt := v.Type()
numFields := v.NumField() numFields := v.NumField()
for i := 0; i < numFields; i++ { for i := 0; i < numFields; i++ {
d.pad() d.indent()
vtf := vt.Field(i) vtf := vt.Field(i)
d.w.Write([]byte(vtf.Name)) d.w.Write([]byte(vtf.Name))
d.w.Write(colonSpaceBytes) d.w.Write(colonSpaceBytes)
d.ignoreNextPad = true d.ignoreNextIndent = true
d.dump(d.unpackValue(v.Field(i))) d.dump(d.unpackValue(v.Field(i)))
if i < (numFields - 1) { if i < (numFields - 1) {
d.w.Write(commaNewlineBytes) d.w.Write(commaNewlineBytes)
@ -279,7 +279,7 @@ func (d *dumpState) dump(v reflect.Value) {
} }
} }
d.depth-- d.depth--
d.pad() d.indent()
d.w.Write(closeBraceBytes) d.w.Write(closeBraceBytes)
case reflect.Uintptr: case reflect.Uintptr: