Skip to content

Commit 023c8e4

Browse files
bicycle1885StefanKarpinski
authored andcommitted
allow chop to take an empty string (#31312)
1 parent 38439d9 commit 023c8e4

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

base/strings/util.jl

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ julia> chop(a, head = 5, tail = 5)
9696
```
9797
"""
9898
function chop(s::AbstractString; head::Integer = 0, tail::Integer = 1)
99+
if isempty(s)
100+
return SubString(s)
101+
end
99102
SubString(s, nextind(s, firstindex(s), head), prevind(s, lastindex(s), tail))
100103
end
101104

test/strings/util.jl

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ end
302302
@test chomp("foo\r\n") == "foo"
303303
@test chomp("fo∀\r\n") == "fo∀"
304304
@test chomp("fo∀") == "fo∀"
305+
@test chop("") == ""
305306
@test chop("fooε") == "foo"
306307
@test chop("foεo") == "foε"
307308
@test chop("∃∃∃∃") == "∃∃∃"

0 commit comments

Comments
 (0)