Update stringy.go

Remove recompilation regexp
This commit is contained in:
Alexey Slivkin 2024-04-12 01:56:13 +03:00 committed by GitHub
parent 82896f05d5
commit b4c25dec91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 3 deletions

View File

@ -10,6 +10,8 @@ import (
"unicode"
)
var matchWordRegexp = regexp.MustCompile(`[\s]*[\W]\pN`)
// input is struct that holds input from user and result
type input struct {
Input string
@ -228,9 +230,8 @@ func (i *input) LcFirst() string {
// Lines returns slice of strings by removing white space characters
func (i *input) Lines() []string {
input := getInput(*i)
matchWord := regexp.MustCompile(`[\s]*[\W]\pN`)
result := matchWord.ReplaceAllString(input, " ")
input := getInput(*i)
result := matchWordRegexp.ReplaceAllString(input, " ")
return strings.Fields(strings.TrimSpace(result))
}