Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more fiddles
  • Loading branch information
ZacLN committed Jan 12, 2021
commit ecca0c6df421ed15855e061abb921d3c8ee2f46e
59 changes: 31 additions & 28 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,36 @@ function get_identifier(x, offset, pos=0)
end
end


if VERSION < v"1.1"
_splitdir_nodrive(path::String) = _splitdir_nodrive("", path)
function _splitdir_nodrive(a::String, b::String)
m = match(Base.Filesystem.path_dir_splitter, b)
m === nothing && return (a, b)
a = string(a, isempty(m.captures[1]) ? m.captures[2][1] : m.captures[1])
a, String(m.captures[3])
end
splitpath(p::AbstractString) = splitpath(String(p))

function splitpath(p::String)
drive, p = _splitdrive(p)
out = String[]
isempty(p) && (pushfirst!(out, p)) # "" means the current directory.
while !isempty(p)
dir, base = _splitdir_nodrive(p)
dir == p && (pushfirst!(out, dir); break) # Reached root node.
if !isempty(base) # Skip trailing '/' in basename
pushfirst!(out, base)
end
p = dir
end
if !isempty(drive) # Tack the drive back on to the first element.
out[1] = drive * out[1] # Note that length(out) is always >= 1.
end
return out
end
end

@static if Sys.iswindows() && VERSION < v"1.3"
function _splitdir_nodrive(a::String, b::String)
m = match(r"^(.*?)([/\\]+)([^/\\]*)$", b)
Expand All @@ -308,6 +338,7 @@ end
else
_dirname = dirname
_splitdir = splitdir
_splitdrive = splitdrive
end

function valid_id(s::String)
Expand Down Expand Up @@ -374,31 +405,3 @@ function is_in_target_dir_of_package(pkgpath, target)
end
end

if VERSION < v"1.1"
_splitdir_nodrive(path::String) = _splitdir_nodrive("", path)
function _splitdir_nodrive(a::String, b::String)
m = match(Base.Filesystem.path_dir_splitter, b)
m === nothing && return (a, b)
a = string(a, isempty(m.captures[1]) ? m.captures[2][1] : m.captures[1])
a, String(m.captures[3])
end
splitpath(p::AbstractString) = splitpath(String(p))

function splitpath(p::String)
drive, p = splitdrive(p)
out = String[]
isempty(p) && (pushfirst!(out, p)) # "" means the current directory.
while !isempty(p)
dir, base = _splitdir_nodrive(p)
dir == p && (pushfirst!(out, dir); break) # Reached root node.
if !isempty(base) # Skip trailing '/' in basename
pushfirst!(out, base)
end
p = dir
end
if !isempty(drive) # Tack the drive back on to the first element.
out[1] = drive * out[1] # Note that length(out) is always >= 1.
end
return out
end
end