From 2d1879a15abc88588c4d30ecc0b85525ab5a5105 Mon Sep 17 00:00:00 2001 From: mars315 <57739378+mars315@users.noreply.github.com> Date: Tue, 16 Jan 2024 11:02:31 +0800 Subject: [PATCH] bugfix --- lib/stringx/string.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) 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 -}