diff options
| author | Patrick Mezard <[email protected]> | 2013-10-28 14:35:33 +0100 |
|---|---|---|
| committer | Patrick Mezard <[email protected]> | 2013-10-28 14:35:33 +0100 |
| commit | 8e1b34364faac53e7da8801da5baf0c0df120a42 (patch) | |
| tree | 88f873e88a3782c3f821c3f502611025c5bb7ba4 /spew/dump.go | |
| parent | 1fdf49f1b9ce7ab182b1b38bbc847b9807f66f3a (diff) | |
dump: make SortKeys default to string representation instead of nothing
The previous version of SortKeys was sorting only native types. Now, if
the type is unknown it defaults to its reflect.Value.String()
representation which at least guarantees display stability.
Diffstat (limited to 'spew/dump.go')
| -rw-r--r-- | spew/dump.go | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/spew/dump.go b/spew/dump.go index c06750d..771b473 100644 --- a/spew/dump.go +++ b/spew/dump.go @@ -269,29 +269,17 @@ func (s *valuesSorter) Less(i, j int) bool { case reflect.Uintptr: return s.values[i].UnsafeAddr() < s.values[j].UnsafeAddr() } - panic("notimplemented") + return s.values[i].String() < s.values[j].String() } // Generic sort function for native types: int, uint, bool, string and uintptr. -// Other inputs are left unchanged. +// Other inputs are sort according to their Value.String() value to ensure +// display stability. func SortValues(values []reflect.Value) { if len(values) == 0 { return } - switch values[0].Kind() { - case reflect.Bool: - sort.Sort(&valuesSorter{values}) - case reflect.Float32, reflect.Float64: - sort.Sort(&valuesSorter{values}) - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - sort.Sort(&valuesSorter{values}) - case reflect.String: - sort.Sort(&valuesSorter{values}) - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: - sort.Sort(&valuesSorter{values}) - case reflect.Uintptr: - sort.Sort(&valuesSorter{values}) - } + sort.Sort(&valuesSorter{values}) } // dump is the main workhorse for dumping a value. It uses the passed reflect |
