@@ -118,21 +118,21 @@ type arrayValue struct{ wrapperValue }
118
118
type mapValue struct { wrapperValue }
119
119
type stringValue struct { wrapperValue }
120
120
121
- func (v arrayValue ) Contains (elem Value ) bool {
122
- rv := reflect .ValueOf (v .value )
123
- e := elem .Interface ()
124
- for i , len := 0 , rv .Len (); i < len ; i ++ {
125
- if Equal (rv .Index (i ).Interface (), e ) {
121
+ func (av arrayValue ) Contains (ev Value ) bool {
122
+ ar := reflect .ValueOf (av .value )
123
+ e := ev .Interface ()
124
+ for i , len := 0 , ar .Len (); i < len ; i ++ {
125
+ if Equal (ar .Index (i ).Interface (), e ) {
126
126
return true
127
127
}
128
128
}
129
129
return false
130
130
}
131
131
132
- func (v arrayValue ) IndexValue (index Value ) Value {
133
- rv := reflect .ValueOf (v .value )
132
+ func (av arrayValue ) IndexValue (iv Value ) Value {
133
+ ar := reflect .ValueOf (av .value )
134
134
var n int
135
- switch ix := index .Interface ().(type ) {
135
+ switch ix := iv .Interface ().(type ) {
136
136
case int :
137
137
n = ix
138
138
case float32 :
@@ -144,80 +144,80 @@ func (v arrayValue) IndexValue(index Value) Value {
144
144
return nilValue
145
145
}
146
146
if n < 0 {
147
- n += rv .Len ()
147
+ n += ar .Len ()
148
148
}
149
- if 0 <= n && n < rv .Len () {
150
- return ValueOf (rv .Index (n ).Interface ())
149
+ if 0 <= n && n < ar .Len () {
150
+ return ValueOf (ar .Index (n ).Interface ())
151
151
}
152
152
return nilValue
153
153
}
154
154
155
- func (v arrayValue ) PropertyValue (index Value ) Value {
156
- rv := reflect .ValueOf (v .value )
157
- switch index .Interface () {
155
+ func (av arrayValue ) PropertyValue (iv Value ) Value {
156
+ ar := reflect .ValueOf (av .value )
157
+ switch iv .Interface () {
158
158
case firstKey :
159
- if rv .Len () > 0 {
160
- return ValueOf (rv .Index (0 ).Interface ())
159
+ if ar .Len () > 0 {
160
+ return ValueOf (ar .Index (0 ).Interface ())
161
161
}
162
162
case lastKey :
163
- if rv .Len () > 0 {
164
- return ValueOf (rv .Index (rv .Len () - 1 ).Interface ())
163
+ if ar .Len () > 0 {
164
+ return ValueOf (ar .Index (ar .Len () - 1 ).Interface ())
165
165
}
166
166
case sizeKey :
167
- return ValueOf (rv .Len ())
167
+ return ValueOf (ar .Len ())
168
168
}
169
169
return nilValue
170
170
}
171
171
172
- func (v mapValue ) Contains (index Value ) bool {
173
- rv := reflect .ValueOf (v .value )
174
- iv := reflect .ValueOf (index .Interface ())
175
- if iv .IsValid () && rv .Type ().Key () == iv .Type () {
176
- return rv .MapIndex (iv ).IsValid ()
172
+ func (mv mapValue ) Contains (iv Value ) bool {
173
+ mr := reflect .ValueOf (mv .value )
174
+ ir := reflect .ValueOf (iv .Interface ())
175
+ if ir .IsValid () && mr .Type ().Key () == ir .Type () {
176
+ return mr .MapIndex (ir ).IsValid ()
177
177
}
178
178
return false
179
179
}
180
180
181
- func (v mapValue ) IndexValue (index Value ) Value {
182
- rv := reflect .ValueOf (v .value )
183
- iv := reflect .ValueOf (index .Interface ())
184
- if iv .IsValid () && iv .Type ().ConvertibleTo (rv .Type ().Key ()) {
185
- ev := rv .MapIndex (iv .Convert (rv .Type ().Key ()))
181
+ func (mv mapValue ) IndexValue (iv Value ) Value {
182
+ mr := reflect .ValueOf (mv .value )
183
+ ir := reflect .ValueOf (iv .Interface ())
184
+ if ir .IsValid () && ir .Type ().ConvertibleTo (mr .Type ().Key ()) {
185
+ ev := mr .MapIndex (ir .Convert (mr .Type ().Key ()))
186
186
if ev .IsValid () {
187
187
return ValueOf (ev .Interface ())
188
188
}
189
189
}
190
190
return nilValue
191
191
}
192
192
193
- func (v mapValue ) PropertyValue (index Value ) Value {
194
- rv := reflect .ValueOf (v .Interface ())
195
- iv := reflect .ValueOf (index .Interface ())
196
- if ! iv .IsValid () {
193
+ func (mv mapValue ) PropertyValue (iv Value ) Value {
194
+ mr := reflect .ValueOf (mv .Interface ())
195
+ ir := reflect .ValueOf (iv .Interface ())
196
+ if ! ir .IsValid () {
197
197
return nilValue
198
198
}
199
- ev := rv .MapIndex (iv )
199
+ ev := mr .MapIndex (ir )
200
200
switch {
201
201
case ev .IsValid ():
202
202
return ValueOf (ev .Interface ())
203
- case index .Interface () == sizeKey :
204
- return ValueOf (rv .Len ())
203
+ case iv .Interface () == sizeKey :
204
+ return ValueOf (mr .Len ())
205
205
default :
206
206
return nilValue
207
207
}
208
208
}
209
209
210
- func (v stringValue ) Contains (substr Value ) bool {
210
+ func (sv stringValue ) Contains (substr Value ) bool {
211
211
s , ok := substr .Interface ().(string )
212
212
if ! ok {
213
213
s = fmt .Sprint (substr .Interface ())
214
214
}
215
- return strings .Contains (v .value .(string ), s )
215
+ return strings .Contains (sv .value .(string ), s )
216
216
}
217
217
218
- func (v stringValue ) PropertyValue (index Value ) Value {
219
- if index .Interface () == sizeKey {
220
- return ValueOf (len (v .value .(string )))
218
+ func (sv stringValue ) PropertyValue (iv Value ) Value {
219
+ if iv .Interface () == sizeKey {
220
+ return ValueOf (len (sv .value .(string )))
221
221
}
222
222
return nilValue
223
223
}
0 commit comments