Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mars315 committed Jan 16, 2024
1 parent d1a3bd7 commit 2d1879a
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/stringx/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ import (
"github.com/mars315/autoflags/lib/builtin"
)

// SafeTokens 切分字符串,去掉空格
// Split Like strings.Split, but remove the spaces from each string.
func Split(s0, sep string) []string {
s := strings.TrimSpace(s0)
l := strings.Split(s, sep)

r := l[:0]
for _, str := range l {
r = append(r, strings.TrimSpace(str))
}

return r
}

// SafeTokens split string, remove spaces, and remove empty strings.
func SafeTokens(cmd string, sep string) []string {
if cmd = strings.TrimSpace(cmd); len(cmd) == 0 {
return nil
Expand Down Expand Up @@ -64,16 +77,3 @@ func AtoSlice[T builtin.SignedInteger](s string, sep string) []T {
}
return l
}

// Split Like strings.Split, but remove the spaces from each string.
func Split(s0, sep string) []string {
s := strings.TrimSpace(s0)
l := strings.Split(s, sep)

r := l[:0]
for _, str := range l {
r = append(r, strings.TrimSpace(str))
}

return r
}

0 comments on commit 2d1879a

Please sign in to comment.