1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 07:08:58 +01:00
liquid/evaluator/arrays.go
2017-07-21 11:56:04 -04:00

22 lines
487 B
Go

package evaluator
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
}
}