Skip to content

Commit a2fdb7d

Browse files
committed
Switch splitpath() to return an Array{String} instead of tuple
1 parent 0e6606d commit a2fdb7d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

base/path.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ function pathsep(paths::AbstractString...)
198198
end
199199

200200
"""
201-
splitpath(path::AbstractString) -> (AbstractString, AbstractString, AbstractString...)
201+
splitpath(path::AbstractString) -> [AbstractString, AbstractString, AbstractString...]
202202
203203
Split a file path into all its path components. This is the opposite of
204-
`joinpath`. Returns a tuple of strings, one for each directory or file in the
205-
path, including the root directory if present.
204+
`joinpath`. Returns an array of substrings, one for each directory or file in
205+
the path, including the root directory if present.
206206
207207
# Examples
208208
```jldoctest
@@ -211,13 +211,15 @@ julia> splitpath("/home/myuser/example.jl")
211211
```
212212
"""
213213
function splitpath(p::AbstractString)
214-
out = ()
214+
out = AbstractString[]
215215
while true
216-
isempty(p) && return out
217-
ismount(p) && return (dirname(p), out...)
216+
isempty(p) && break
217+
ismount(p) && (push!(out, dirname(p)); break)
218218
isempty(basename(p)) && (p = dirname(p); continue) # Trailing '/'.
219-
(p, out) = dirname(p), (basename(p), out...)
219+
push!(out, basename(p))
220+
p = dirname(p)
220221
end
222+
return reverse(out)
221223
end
222224

223225
joinpath(a::AbstractString) = a

0 commit comments

Comments
 (0)