summaryrefslogtreecommitdiff
path: root/spew/dump.go
diff options
context:
space:
mode:
authorDave Collins <[email protected]>2013-01-10 20:31:03 -0600
committerDave Collins <[email protected]>2013-01-10 20:39:05 -0600
commit184d118062e467401f87c22ea4034135cf508529 (patch)
tree9ebc419e52747bff3f6901b15ce3793a30258cbc /spew/dump.go
parent04998fcda361bb6a087d58560bfa03ec3038529f (diff)
Add config pointers to format and dump states.
This paves the way to support individual configuration options through a separate type while still providing the simple global config and package level methods.
Diffstat (limited to 'spew/dump.go')
-rw-r--r--spew/dump.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/spew/dump.go b/spew/dump.go
index 7b5d87c..067f98e 100644
--- a/spew/dump.go
+++ b/spew/dump.go
@@ -32,16 +32,17 @@ type dumpState struct {
pointers map[uintptr]int
ignoreNextType bool
ignoreNextPad bool
+ cs *ConfigState
}
-// pad performs indentation according to the depth level and Config.Indent
+// pad performs indentation according to the depth level and cs.Indent
// option.
func (d *dumpState) pad() {
if d.ignoreNextPad {
d.ignoreNextPad = false
return
}
- d.w.Write(bytes.Repeat([]byte(Config.Indent), d.depth))
+ d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth))
}
// dumpPtr handles formatting of pointers by indirecting them as necessary.
@@ -146,9 +147,9 @@ func (d *dumpState) dump(v reflect.Value) {
// Call error/Stringer interfaces if they exist and the handle methods flag
// is enabled
- if !Config.DisableMethods {
+ if !d.cs.DisableMethods {
if (kind != reflect.Invalid) && (kind != reflect.Interface) {
- if handled := handleMethods(d.w, v); handled {
+ if handled := handleMethods(d.cs, d.w, v); handled {
return
}
}
@@ -182,7 +183,7 @@ func (d *dumpState) dump(v reflect.Value) {
case reflect.Array, reflect.Slice:
d.w.Write(openBraceNewlineBytes)
d.depth++
- if (Config.MaxDepth != 0) && (d.depth > Config.MaxDepth) {
+ if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
d.pad()
d.w.Write(maxNewlineBytes)
} else {
@@ -213,7 +214,7 @@ func (d *dumpState) dump(v reflect.Value) {
case reflect.Map:
d.w.Write(openBraceNewlineBytes)
d.depth++
- if (Config.MaxDepth != 0) && (d.depth > Config.MaxDepth) {
+ if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
d.pad()
d.w.Write(maxNewlineBytes)
} else {
@@ -238,7 +239,7 @@ func (d *dumpState) dump(v reflect.Value) {
case reflect.Struct:
d.w.Write(openBraceNewlineBytes)
d.depth++
- if (Config.MaxDepth != 0) && (d.depth > Config.MaxDepth) {
+ if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
d.pad()
d.w.Write(maxNewlineBytes)
} else {
@@ -291,7 +292,7 @@ func Fdump(w io.Writer, a ...interface{}) {
continue
}
- d := dumpState{w: w}
+ d := dumpState{w: w, cs: &Config}
d.pointers = make(map[uintptr]int)
d.dump(reflect.ValueOf(arg))
d.w.Write(newlineBytes)