Added all source files
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// utils.go
|
||||
package expr
|
||||
|
||||
func isString(v any) (ok bool) {
|
||||
_, ok = v.(string)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isInteger(v any) (ok bool) {
|
||||
_, ok = v.(int64)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isFloat(v any) (ok bool) {
|
||||
_, ok = v.(float64)
|
||||
return ok
|
||||
}
|
||||
|
||||
func isNumber(v any) (ok bool) {
|
||||
return isFloat(v) || isInteger(v)
|
||||
}
|
||||
|
||||
func isNumberString(v any) (ok bool) {
|
||||
return isString(v) || isNumber(v)
|
||||
}
|
||||
|
||||
func numAsFloat(v any) (f float64) {
|
||||
var ok bool
|
||||
if f, ok = v.(float64); !ok {
|
||||
i, _ := v.(int64)
|
||||
f = float64(i)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func toBool(v any) (b bool, ok bool) {
|
||||
ok = true
|
||||
switch x := v.(type) {
|
||||
case string:
|
||||
b = len(x) > 0
|
||||
case float64:
|
||||
b = x != 0.0
|
||||
case int64:
|
||||
b = x != 0
|
||||
case bool:
|
||||
b = x
|
||||
default:
|
||||
ok = false
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user