1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-02 21:17:48 +01:00
liquid/values/arrays.go
2017-07-27 18:11:37 -04:00

22 lines
484 B
Go

package values
import (
"reflect"
)
// TODO Length is now only used by the "size" filter.
// Maybe it should go somewhere else.
// Length returns the length of a string or array. In keeping with Liquid semantics,
// and contra Go, it does not return the size of a map.
func Length(value interface{}) int {
value = ToLiquid(value)
ref := reflect.ValueOf(value)
switch ref.Kind() {
case reflect.Array, reflect.Slice, reflect.String:
return ref.Len()
default:
return 0
}
}