Skip to content

Commit

Permalink
Update string.go (#496)
Browse files Browse the repository at this point in the history
* Update string.go

more reasonable

* test
  • Loading branch information
liujundezhanghao authored Jul 17, 2024
1 parent f6f43fb commit 1ca9c7b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion string.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func Substring[T ~string](str T, offset int, length uint) T {
}
}

if offset > size {
if offset >= size {
return Empty[T]()
}

Expand Down
2 changes: 2 additions & 0 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func TestSubstring(t *testing.T) {
str12 := Substring("hello", -4, math.MaxUint)
str13 := Substring("🏠🐶🐱", 0, 2)
str14 := Substring("你好,世界", 0, 3)
str15 := Substring("hello", 5, 1)

is.Equal("", str1)
is.Equal("", str2)
Expand All @@ -91,6 +92,7 @@ func TestSubstring(t *testing.T) {
is.Equal("ello", str12)
is.Equal("🏠🐶", str13)
is.Equal("你好,", str14)
is.Equal("", str15)
}

func TestRuneLength(t *testing.T) {
Expand Down

0 comments on commit 1ca9c7b

Please sign in to comment.