1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-02 14:37:50 +01:00
liquid/values/arrays.go

22 lines
484 B
Go
Raw Normal View History

2017-07-28 00:11:37 +02:00
package values
2017-06-27 16:28:39 +02:00
import (
"reflect"
)
2017-07-21 17:56:04 +02:00
// TODO Length is now only used by the "size" filter.
// Maybe it should go somewhere else.
2017-06-28 20:41:46 +02:00
// 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 {
2017-07-03 18:00:43 +02:00
value = ToLiquid(value)
2017-06-28 20:41:46 +02:00
ref := reflect.ValueOf(value)
switch ref.Kind() {
2017-06-28 23:18:48 +02:00
case reflect.Array, reflect.Slice, reflect.String:
return ref.Len()
default:
2017-06-28 20:41:46 +02:00
return 0
}
}