Skip to content

Commit

Permalink
Merge pull request #26 from alexey-slivkin/patch-1
Browse files Browse the repository at this point in the history
Removed regexp recompilation for each helper run
  • Loading branch information
gobeam authored Apr 23, 2024
2 parents 9dd1f5c + b4c25de commit 3769c2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions stringy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}

Expand Down

0 comments on commit 3769c2b

Please sign in to comment.