-
Notifications
You must be signed in to change notification settings - Fork 1
/
op_contain.go
43 lines (31 loc) · 891 Bytes
/
op_contain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package cond
import (
"reflect"
)
const opContain Operator = "$contain"
func opContainFunc(s *State, l string, op Operator, r interface{}, reg map[string]interface{}) bool {
lVal := s.loadValFromSession(l, reg)
if lVal == nil {
return false
}
//rType := reflect.TypeOf(r)
lType := reflect.TypeOf(lVal)
if lType.Kind() != reflect.Slice {
panic("$contain left value must be a slice")
}
lElementType := lType.Elem()
if lElementType.Kind() == reflect.Interface {
panic("$contain: type of left value can not be []interface{}")
}
//if getValType(rType.Kind()) != getValType(lElementType.Kind()) {
// panic("$contain: type mismatch between left value & right value")
//}
lValue := reflect.ValueOf(lVal)
for i := 0; i < lValue.Len(); i++ {
lrIndex := lValue.Index(i).Interface()
if compareValue(s, opEQ, r, lrIndex, reg) {
return true
}
}
return false
}