From a2fdb7d078f9281bbaf49133cf37f1344ab76b59 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Tue, 17 Jul 2018 18:32:32 -0400 Subject: [PATCH] Switch splitpath() to return an Array{String} instead of tuple --- base/path.jl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/base/path.jl b/base/path.jl index 1a2279870e0f34..91fa6ffb9fa5a5 100644 --- a/base/path.jl +++ b/base/path.jl @@ -198,11 +198,11 @@ function pathsep(paths::AbstractString...) end """ - splitpath(path::AbstractString) -> (AbstractString, AbstractString, AbstractString...) + splitpath(path::AbstractString) -> [AbstractString, AbstractString, AbstractString...] Split a file path into all its path components. This is the opposite of -`joinpath`. Returns a tuple of strings, one for each directory or file in the -path, including the root directory if present. +`joinpath`. Returns an array of substrings, one for each directory or file in +the path, including the root directory if present. # Examples ```jldoctest @@ -211,13 +211,15 @@ julia> splitpath("/home/myuser/example.jl") ``` """ function splitpath(p::AbstractString) - out = () + out = AbstractString[] while true - isempty(p) && return out - ismount(p) && return (dirname(p), out...) + isempty(p) && break + ismount(p) && (push!(out, dirname(p)); break) isempty(basename(p)) && (p = dirname(p); continue) # Trailing '/'. - (p, out) = dirname(p), (basename(p), out...) + push!(out, basename(p)) + p = dirname(p) end + return reverse(out) end joinpath(a::AbstractString) = a