Add StringTitle
This commit is contained in:
@@ -3,10 +3,19 @@ package commons
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
var caserTitle cases.Caser = cases.Title(language.English)
|
||||
|
||||
var whitespace = regexp.MustCompile(`\s+`)
|
||||
|
||||
func StringTitle(s string) string {
|
||||
return caserTitle.String(s)
|
||||
}
|
||||
|
||||
// StringNormalize will replace arbitrary lengths of consecutive white space with a single one.
|
||||
func StringNormalize(s string) string {
|
||||
s = whitespace.ReplaceAllString(s, " ")
|
||||
|
||||
Reference in New Issue
Block a user