Skip to content

Commit

Permalink
fix: utils.Trim should trim all string content (#1775)
Browse files Browse the repository at this point in the history
* fix: `utils.Trim` should trim all string content

* add empty string input

* better fix
  • Loading branch information
trim21 committed Feb 14, 2022
1 parent 937713e commit 391ae59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils/strings.go
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions utils/strings_test.go
Expand Up @@ -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) {
Expand Down

0 comments on commit 391ae59

Please sign in to comment.