diff --git a/lib/stringx/string.go b/lib/stringx/string.go index 2945771..bed1a38 100644 --- a/lib/stringx/string.go +++ b/lib/stringx/string.go @@ -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 @@ -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 -}