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
// detection.
// detection.
type xref1 struct {
ps2 *xref2
}

View File

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