Support slices of strings
This commit is contained in:
parent
9929660465
commit
360e7bb0f1
42
spew/dump.go
42
spew/dump.go
|
@ -435,28 +435,14 @@ func (d *dumpState) dump(v reflect.Value) {
|
||||||
d.ignoreNextIndent = true
|
d.ignoreNextIndent = true
|
||||||
val := d.unpackValue(v.Field(i))
|
val := d.unpackValue(v.Field(i))
|
||||||
if tag != "" {
|
if tag != "" {
|
||||||
if val.Type().Kind() != reflect.String || (val.Type().Kind() == reflect.Ptr && val.Type().Elem().Kind() == reflect.String) {
|
if val.Type().Kind() != reflect.String || ((val.Type().Kind() == reflect.Ptr || val.Type().Kind() == reflect.Slice) && val.Type().Elem().Kind() == reflect.String) {
|
||||||
var newVal string
|
|
||||||
if val.Type().Kind() == reflect.Ptr {
|
|
||||||
newVal = val.Elem().String()
|
|
||||||
} else {
|
|
||||||
newVal = val.String()
|
|
||||||
}
|
|
||||||
tags := strings.Split(tag, ",")
|
tags := strings.Split(tag, ",")
|
||||||
for _, tag := range tags {
|
if val.Type().Kind() == reflect.Slice {
|
||||||
if tag == "normalize" {
|
for i := 0; i < val.Len(); i++ {
|
||||||
newVal = normalize(newVal)
|
applyTags(val.Index(i), tags...)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for _, tag := range tags {
|
|
||||||
if tag == "hash" {
|
|
||||||
newVal = hash(newVal)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if val.Type().Kind() == reflect.Ptr {
|
|
||||||
val.Elem().SetString(newVal)
|
|
||||||
} else {
|
} else {
|
||||||
val.SetString(newVal)
|
applyTags(val, tags...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,6 +474,24 @@ func (d *dumpState) dump(v reflect.Value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyTags(val reflect.Value, tags ...string) {
|
||||||
|
if val.Type().Kind() == reflect.Ptr {
|
||||||
|
val = val.Elem()
|
||||||
|
}
|
||||||
|
newVal := val.String()
|
||||||
|
for _, tag := range tags {
|
||||||
|
if tag == "normalize" {
|
||||||
|
newVal = normalize(newVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, tag := range tags {
|
||||||
|
if tag == "hash" {
|
||||||
|
newVal = hash(newVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val.SetString(newVal)
|
||||||
|
}
|
||||||
|
|
||||||
func normalize(str string) string {
|
func normalize(str string) string {
|
||||||
return emails.Normalize(str)
|
return emails.Normalize(str)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue