summaryrefslogtreecommitdiffstats
path: root/common/hreflect/helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/hreflect/helpers.go')
-rw-r--r--common/hreflect/helpers.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/common/hreflect/helpers.go b/common/hreflect/helpers.go
index db7b208b5..d936da19c 100644
--- a/common/hreflect/helpers.go
+++ b/common/hreflect/helpers.go
@@ -22,6 +22,42 @@ import (
"github.com/gohugoio/hugo/common/types"
)
+// TODO(bep) replace the private versions in /tpl with these.
+// IsInt returns whether the given kind is a number.
+func IsNumber(kind reflect.Kind) bool {
+ return IsInt(kind) || IsUint(kind) || IsFloat(kind)
+}
+
+// IsInt returns whether the given kind is an int.
+func IsInt(kind reflect.Kind) bool {
+ switch kind {
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+ return true
+ default:
+ return false
+ }
+}
+
+// IsUint returns whether the given kind is an uint.
+func IsUint(kind reflect.Kind) bool {
+ switch kind {
+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
+ return true
+ default:
+ return false
+ }
+}
+
+// IsFloat returns whether the given kind is a float.
+func IsFloat(kind reflect.Kind) bool {
+ switch kind {
+ case reflect.Float32, reflect.Float64:
+ return true
+ default:
+ return false
+ }
+}
+
// IsTruthful returns whether in represents a truthful value.
// See IsTruthfulValue
func IsTruthful(in interface{}) bool {