mirror of https://github.com/gobeam/stringy.git
Merge pull request #26 from alexey-slivkin/patch-1
Removed regexp recompilation for each helper run
This commit is contained in:
commit
3769c2b2bb
|
@ -7,10 +7,11 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var selectCapitalRegexp = regexp.MustCompile(SelectCapital)
|
||||||
|
|
||||||
func caseHelper(input string, isCamel bool, rule ...string) []string {
|
func caseHelper(input string, isCamel bool, rule ...string) []string {
|
||||||
if !isCamel {
|
if !isCamel {
|
||||||
re := regexp.MustCompile(SelectCapital)
|
input = selectCapitalRegexp.ReplaceAllString(input, ReplaceCapital)
|
||||||
input = re.ReplaceAllString(input, ReplaceCapital)
|
|
||||||
}
|
}
|
||||||
input = strings.Join(strings.Fields(strings.TrimSpace(input)), " ")
|
input = strings.Join(strings.Fields(strings.TrimSpace(input)), " ")
|
||||||
if len(rule) > 0 && len(rule)%2 != 0 {
|
if len(rule) > 0 && len(rule)%2 != 0 {
|
||||||
|
|
|
@ -10,6 +10,8 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var matchWordRegexp = regexp.MustCompile(`[\s]*[\W]\pN`)
|
||||||
|
|
||||||
// input is struct that holds input from user and result
|
// input is struct that holds input from user and result
|
||||||
type input struct {
|
type input struct {
|
||||||
Input string
|
Input string
|
||||||
|
@ -228,9 +230,8 @@ func (i *input) LcFirst() string {
|
||||||
|
|
||||||
// Lines returns slice of strings by removing white space characters
|
// Lines returns slice of strings by removing white space characters
|
||||||
func (i *input) Lines() []string {
|
func (i *input) Lines() []string {
|
||||||
input := getInput(*i)
|
input := getInput(*i)
|
||||||
matchWord := regexp.MustCompile(`[\s]*[\W]\pN`)
|
result := matchWordRegexp.ReplaceAllString(input, " ")
|
||||||
result := matchWord.ReplaceAllString(input, " ")
|
|
||||||
return strings.Fields(strings.TrimSpace(result))
|
return strings.Fields(strings.TrimSpace(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue