mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 00:55:32 +00:00
Suche: HTMX + Webseite
This commit is contained in:
45
helpers/datatypes/string.go
Normal file
45
helpers/datatypes/string.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package datatypes
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var html_regexp = regexp.MustCompile(`<[^>]+>`)
|
||||
var ws_regexp = regexp.MustCompile(`\s+`)
|
||||
|
||||
func DeleteTags(s string) string {
|
||||
return html_regexp.ReplaceAllString(s, "")
|
||||
}
|
||||
|
||||
func NormalizeString(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
s = strings.ReplaceAll(s, "<div>", "")
|
||||
s = strings.ReplaceAll(s, "</div>", "")
|
||||
return s
|
||||
}
|
||||
|
||||
func SliceJoin[T any](slice []T, join string, f func(T) string) string {
|
||||
var result []string
|
||||
for _, item := range slice {
|
||||
ap := f(item)
|
||||
if ap != "" {
|
||||
result = append(result, ap)
|
||||
}
|
||||
}
|
||||
return strings.Join(result, join)
|
||||
}
|
||||
|
||||
func RemovePunctuation(s string) string {
|
||||
return strings.Map(func(r rune) rune {
|
||||
if unicode.IsPunct(r) {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}, s)
|
||||
}
|
||||
|
||||
func NormalizeWhitespace(s string) string {
|
||||
return strings.TrimSpace(ws_regexp.ReplaceAllString(s, " "))
|
||||
}
|
||||
Reference in New Issue
Block a user