Quellcode durchsuchen

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.
Dave Collins vor 13 Jahren
Ursprung
Commit
52f41f689f
2 geänderte Dateien mit 22 neuen und 22 gelöschten Zeilen
  1. 1 1
      spew/common_test.go
  2. 21 21
      spew/dump.go

+ 1 - 1
spew/common_test.go

@@ -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
 }
 }

+ 21 - 21
spew/dump.go

@@ -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
-	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.
 // option.
-func (d *dumpState) pad() {
-	if d.ignoreNextPad {
-		d.ignoreNextPad = false
+func (d *dumpState) indent() {
+	if d.ignoreNextIndent {
+		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: