MCPcopy
hub / github.com/flosch/pongo2 / IsTrue

Method IsTrue

value.go:217–235  ·  view source on GitHub ↗

IsTrue tries to evaluate the underlying value the Pythonic-way: Returns TRUE in one the following cases: * int != 0 * uint != 0 * float != 0.0 * len(array/chan/map/slice/string) > 0 * bool == true * underlying value is a struct Otherwise returns always FALSE.

()

Source from the content-addressed store, hash-verified

215//
216// Otherwise returns always FALSE.
217func (v *Value) IsTrue() bool {
218 switch v.getResolvedValue().Kind() {
219 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
220 return v.getResolvedValue().Int() != 0
221 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
222 return v.getResolvedValue().Uint() != 0
223 case reflect.Float32, reflect.Float64:
224 return v.getResolvedValue().Float() != 0
225 case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String:
226 return v.getResolvedValue().Len() > 0
227 case reflect.Bool:
228 return v.getResolvedValue().Bool()
229 case reflect.Struct:
230 return true // struct instance is always true
231 default:
232 logf("Value.IsTrue() not available for type: %s\n", v.getResolvedValue().Kind().String())
233 return false
234 }
235}
236
237// Negate tries to negate the underlying value. It's mainly used for
238// the NOT-operator and in conjunction with a call to

Callers 5

ExecuteMethod · 0.80
EvaluateMethod · 0.80
ExecuteMethod · 0.80
filterDefaultFunction · 0.80
filterYesnoFunction · 0.80

Calls 6

getResolvedValueMethod · 0.95
logfFunction · 0.85
FloatMethod · 0.80
BoolMethod · 0.80
LenMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected