aboutsummaryrefslogtreecommitdiffstats
path: root/modules/util/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/util/util.go')
-rw-r--r--modules/util/util.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/util/util.go b/modules/util/util.go
index 0e5c6a4e64..28b549f405 100644
--- a/modules/util/util.go
+++ b/modules/util/util.go
@@ -11,6 +11,8 @@ import (
"strconv"
"strings"
+ "code.gitea.io/gitea/modules/optional"
+
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
@@ -42,6 +44,22 @@ func (o OptionalBool) IsNone() bool {
return o == OptionalBoolNone
}
+// ToGeneric converts OptionalBool to optional.Option[bool]
+func (o OptionalBool) ToGeneric() optional.Option[bool] {
+ if o.IsNone() {
+ return optional.None[bool]()
+ }
+ return optional.Some[bool](o.IsTrue())
+}
+
+// OptionalBoolFromGeneric converts optional.Option[bool] to OptionalBool
+func OptionalBoolFromGeneric(o optional.Option[bool]) OptionalBool {
+ if o.Has() {
+ return OptionalBoolOf(o.Value())
+ }
+ return OptionalBoolNone
+}
+
// OptionalBoolOf get the corresponding OptionalBool of a bool
func OptionalBoolOf(b bool) OptionalBool {
if b {