fix: `utils.Trim` should trim all string content (#1775)

* fix: `utils.Trim` should trim all string content

* add empty string input

* better fix
pull/1779/head
Trim21 2022-02-14 15:01:15 +08:00 committed by GitHub
parent 937713e41e
commit 391ae594d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -43,7 +43,7 @@ func Trim(s string, cutset byte) string {
break
}
}
for ; i < j; j-- {
for ; i <= j; j-- {
if s[j] != cutset {
break
}

View File

@ -126,6 +126,15 @@ func Test_Trim(t *testing.T) {
res = Trim(".test", '.')
AssertEqual(t, "test", res)
res = Trim(" ", ' ')
AssertEqual(t, "", res)
res = Trim(" ", ' ')
AssertEqual(t, "", res)
res = Trim("", ' ')
AssertEqual(t, "", res)
}
func Benchmark_Trim(b *testing.B) {