Skip to content

Commit d27c839

Browse files
committed
variable names
1 parent 1a12f12 commit d27c839

File tree

2 files changed

+74
-74
lines changed

2 files changed

+74
-74
lines changed

values/structvalue.go

+33-33
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,57 @@ import (
66

77
type structValue struct{ wrapperValue }
88

9-
func (v structValue) IndexValue(index Value) Value {
10-
return v.PropertyValue(index)
9+
func (sv structValue) IndexValue(index Value) Value {
10+
return sv.PropertyValue(index)
1111
}
1212

13-
func (v structValue) Contains(elem Value) bool {
13+
func (sv structValue) Contains(elem Value) bool {
1414
name, ok := elem.Interface().(string)
1515
if !ok {
1616
return false
1717
}
18-
rt := reflect.TypeOf(v.value)
19-
if rt.Kind() == reflect.Ptr {
20-
if _, found := rt.MethodByName(name); found {
18+
st := reflect.TypeOf(sv.value)
19+
if st.Kind() == reflect.Ptr {
20+
if _, found := st.MethodByName(name); found {
2121
return true
2222
}
23-
rt = rt.Elem()
23+
st = st.Elem()
2424
}
25-
if _, found := rt.MethodByName(name); found {
25+
if _, found := st.MethodByName(name); found {
2626
return true
2727
}
28-
if _, found := v.findField(name); found {
28+
if _, found := sv.findField(name); found {
2929
return true
3030
}
3131
return false
3232
}
3333

34-
func (v structValue) PropertyValue(index Value) Value {
34+
func (sv structValue) PropertyValue(index Value) Value {
3535
name, ok := index.Interface().(string)
3636
if !ok {
3737
return nilValue
3838
}
39-
rv := reflect.ValueOf(v.value)
40-
rt := reflect.TypeOf(v.value)
41-
if rt.Kind() == reflect.Ptr {
42-
if _, found := rt.MethodByName(name); found {
43-
m := rv.MethodByName(name)
44-
return v.invoke(m)
39+
sr := reflect.ValueOf(sv.value)
40+
st := reflect.TypeOf(sv.value)
41+
if st.Kind() == reflect.Ptr {
42+
if _, found := st.MethodByName(name); found {
43+
m := sr.MethodByName(name)
44+
return sv.invoke(m)
4545
}
46-
rt = rt.Elem()
47-
rv = rv.Elem()
48-
if !rv.IsValid() {
46+
st = st.Elem()
47+
sr = sr.Elem()
48+
if !sr.IsValid() {
4949
return nilValue
5050
}
5151
}
52-
if _, found := rt.MethodByName(name); found {
53-
m := rv.MethodByName(name)
54-
return v.invoke(m)
52+
if _, ok := st.MethodByName(name); ok {
53+
m := sr.MethodByName(name)
54+
return sv.invoke(m)
5555
}
56-
if field, found := v.findField(name); found {
57-
fv := rv.FieldByName(field.Name)
56+
if field, ok := sv.findField(name); ok {
57+
fv := sr.FieldByName(field.Name)
5858
if fv.Kind() == reflect.Func {
59-
return v.invoke(fv)
59+
return sv.invoke(fv)
6060
}
6161
return ValueOf(fv.Interface())
6262
}
@@ -66,26 +66,26 @@ func (v structValue) PropertyValue(index Value) Value {
6666
const tagKey = "liquid"
6767

6868
// like FieldByName, but obeys `liquid:"name"` tags
69-
func (v structValue) findField(name string) (*reflect.StructField, bool) {
70-
rt := reflect.TypeOf(v.value)
71-
if rt.Kind() == reflect.Ptr {
72-
rt = rt.Elem()
69+
func (sv structValue) findField(name string) (*reflect.StructField, bool) {
70+
sr := reflect.TypeOf(sv.value)
71+
if sr.Kind() == reflect.Ptr {
72+
sr = sr.Elem()
7373
}
74-
if field, found := rt.FieldByName(name); found {
74+
if field, ok := sr.FieldByName(name); ok {
7575
if _, ok := field.Tag.Lookup(tagKey); !ok {
7676
return &field, true
7777
}
7878
}
79-
for i, n := 0, rt.NumField(); i < n; i++ {
80-
field := rt.Field(i)
79+
for i, n := 0, sr.NumField(); i < n; i++ {
80+
field := sr.Field(i)
8181
if field.Tag.Get(tagKey) == name {
8282
return &field, true
8383
}
8484
}
8585
return nil, false
8686
}
8787

88-
func (v structValue) invoke(fv reflect.Value) Value {
88+
func (sv structValue) invoke(fv reflect.Value) Value {
8989
if fv.IsNil() {
9090
return nilValue
9191
}

values/value.go

+41-41
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,21 @@ type arrayValue struct{ wrapperValue }
118118
type mapValue struct{ wrapperValue }
119119
type stringValue struct{ wrapperValue }
120120

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) {
126126
return true
127127
}
128128
}
129129
return false
130130
}
131131

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)
134134
var n int
135-
switch ix := index.Interface().(type) {
135+
switch ix := iv.Interface().(type) {
136136
case int:
137137
n = ix
138138
case float32:
@@ -144,80 +144,80 @@ func (v arrayValue) IndexValue(index Value) Value {
144144
return nilValue
145145
}
146146
if n < 0 {
147-
n += rv.Len()
147+
n += ar.Len()
148148
}
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())
151151
}
152152
return nilValue
153153
}
154154

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() {
158158
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())
161161
}
162162
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())
165165
}
166166
case sizeKey:
167-
return ValueOf(rv.Len())
167+
return ValueOf(ar.Len())
168168
}
169169
return nilValue
170170
}
171171

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()
177177
}
178178
return false
179179
}
180180

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()))
186186
if ev.IsValid() {
187187
return ValueOf(ev.Interface())
188188
}
189189
}
190190
return nilValue
191191
}
192192

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() {
197197
return nilValue
198198
}
199-
ev := rv.MapIndex(iv)
199+
ev := mr.MapIndex(ir)
200200
switch {
201201
case ev.IsValid():
202202
return ValueOf(ev.Interface())
203-
case index.Interface() == sizeKey:
204-
return ValueOf(rv.Len())
203+
case iv.Interface() == sizeKey:
204+
return ValueOf(mr.Len())
205205
default:
206206
return nilValue
207207
}
208208
}
209209

210-
func (v stringValue) Contains(substr Value) bool {
210+
func (sv stringValue) Contains(substr Value) bool {
211211
s, ok := substr.Interface().(string)
212212
if !ok {
213213
s = fmt.Sprint(substr.Interface())
214214
}
215-
return strings.Contains(v.value.(string), s)
215+
return strings.Contains(sv.value.(string), s)
216216
}
217217

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)))
221221
}
222222
return nilValue
223223
}

0 commit comments

Comments
 (0)