mirror of
https://github.com/danog/liquid.git
synced 2024-11-30 08:39:01 +01:00
22 lines
487 B
Go
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
|
|
}
|
|
}
|