Update helper.go

Performance boost
This commit is contained in:
Alexey Slivkin 2024-04-12 01:44:31 +03:00 committed by GitHub
parent 9dd1f5ca32
commit 82896f05d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 2 deletions

View File

@ -7,10 +7,11 @@ import (
"unicode"
)
var selectCapitalRegexp = regexp.MustCompile(SelectCapital)
func caseHelper(input string, isCamel bool, rule ...string) []string {
if !isCamel {
re := regexp.MustCompile(SelectCapital)
input = re.ReplaceAllString(input, ReplaceCapital)
input = selectCapitalRegexp.ReplaceAllString(input, ReplaceCapital)
}
input = strings.Join(strings.Fields(strings.TrimSpace(input)), " ")
if len(rule) > 0 && len(rule)%2 != 0 {