diff options
Diffstat (limited to 'modules/templates/util_string.go')
-rw-r--r-- | modules/templates/util_string.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/templates/util_string.go b/modules/templates/util_string.go index 2771b1e223..479b755da1 100644 --- a/modules/templates/util_string.go +++ b/modules/templates/util_string.go @@ -4,6 +4,8 @@ package templates import ( + "fmt" + "html/template" "strings" "code.gitea.io/gitea/modules/base" @@ -17,6 +19,19 @@ func NewStringUtils() *StringUtils { return &stringUtils } +func (su *StringUtils) ToString(v any) string { + switch v := v.(type) { + case string: + return v + case template.HTML: + return string(v) + case fmt.Stringer: + return v.String() + default: + return fmt.Sprint(v) + } +} + func (su *StringUtils) HasPrefix(s, prefix string) bool { return strings.HasPrefix(s, prefix) } |