diff options
| author | Josh Rickmar <[email protected]> | 2014-05-05 22:09:56 -0500 |
|---|---|---|
| committer | Dave Collins <[email protected]> | 2014-05-05 22:39:05 -0500 |
| commit | 3fdaf5cea8d23107b993d363e98992fa529dd713 (patch) | |
| tree | 621df5e9073ac8733da24f852c6ce3df8c135fc7 /spew/dump.go | |
| parent | 9ed19f9b0c9116d712e32dee78f1704cb9fc5b02 (diff) | |
Dump non-zero len and cap for applicable types.
Closes #16.
Diffstat (limited to 'spew/dump.go')
| -rw-r--r-- | spew/dump.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spew/dump.go b/spew/dump.go index 3d57306..02d4c9d 100644 --- a/spew/dump.go +++ b/spew/dump.go @@ -270,6 +270,32 @@ func (d *dumpState) dump(v reflect.Value) { } d.ignoreNextType = false + // Display length and capacity if the built-in len and cap functions + // work with the value's kind and the len/cap itself is non-zero. + valueLen, valueCap := 0, 0 + switch v.Kind() { + case reflect.Array, reflect.Slice, reflect.Chan: + valueLen, valueCap = v.Len(), v.Cap() + case reflect.Map, reflect.String: + valueLen = v.Len() + } + if valueLen != 0 || valueCap != 0 { + d.w.Write(openParenBytes) + if valueLen != 0 { + d.w.Write(lenEqualsBytes) + printInt(d.w, int64(valueLen), 10) + } + if valueCap != 0 { + if valueLen != 0 { + d.w.Write(spaceBytes) + } + d.w.Write(capEqualsBytes) + printInt(d.w, int64(valueCap), 10) + } + d.w.Write(closeParenBytes) + d.w.Write(spaceBytes) + } + // Call Stringer/error interfaces if they exist and the handle methods flag // is enabled if !d.cs.DisableMethods { |
