summaryrefslogtreecommitdiff
path: root/spew/dump.go
diff options
context:
space:
mode:
Diffstat (limited to 'spew/dump.go')
-rw-r--r--spew/dump.go26
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 {