Skip to content

Commit cb07aa4

Browse files
committed
flag: replace regexp use
Commit ec05a8d introduces the only (non-test) user of regexp package. It is pretty easy to not use regexp here, so let's get rid of it. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 6a8503d commit cb07aa4

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

flag.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cli
33
import (
44
"context"
55
"fmt"
6-
"regexp"
76
"slices"
87
"strings"
98
"time"
@@ -17,11 +16,7 @@ const (
1716
disableSliceFlagSeparator = false
1817
)
1918

20-
var (
21-
slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano())
22-
23-
commaWhitespace = regexp.MustCompile("[, ]+.*")
24-
)
19+
var slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano())
2520

2621
// GenerateShellCompletionFlag enables shell completion
2722
var GenerateShellCompletionFlag Flag = &BoolFlag{
@@ -202,7 +197,11 @@ func FlagNames(name string, aliases []string) []string {
202197
// Strip off anything after the first found comma or space, which
203198
// *hopefully* makes it a tiny bit more obvious that unexpected behavior is
204199
// caused by using the v1 form of stringly typed "Name".
205-
ret = append(ret, commaWhitespace.ReplaceAllString(part, ""))
200+
if i := strings.IndexAny(part, ", "); i >= 0 {
201+
ret = append(ret, part[:i])
202+
} else {
203+
ret = append(ret, part)
204+
}
206205
}
207206

208207
return ret

0 commit comments

Comments
 (0)