June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,27 +1,20 @@
|
|||
function commonpath{T<:String}(ds::Array{T,1}, delim::Char='/')
|
||||
0 < length(ds) || return convert(T, "")
|
||||
1 < length(ds) || return ds[1]
|
||||
p = split(ds[1], delim)
|
||||
mcnt = length(p)
|
||||
function commonpath(ds::Vector{<:AbstractString}, dlm::Char='/')
|
||||
0 < length(ds) || return ""
|
||||
1 < length(ds) || return String(ds[1])
|
||||
p = split(ds[1], dlm)
|
||||
mincnt = length(p)
|
||||
for d in ds[2:end]
|
||||
q = split(d, delim)
|
||||
mcnt = min(mcnt, length(q))
|
||||
hits = findfirst(p[1:mcnt] .== q[1:mcnt], false)
|
||||
hits != 0 || continue
|
||||
mcnt = hits - 1
|
||||
mcnt != 0 || return convert(T, "")
|
||||
q = split(d, dlm)
|
||||
mincnt = min(mincnt, length(q))
|
||||
hits = findfirst(p[1:mincnt] .!= q[1:mincnt])
|
||||
if hits != 0 mincnt = hits - 1 end
|
||||
if mincnt == 0 return "" end
|
||||
end
|
||||
1 < mcnt || p[1] != "" || return convert(T, string(delim))
|
||||
convert(T, join(p[1:mcnt], delim))
|
||||
1 < mincnt || p[1] != "" || return convert(T, string(dlm))
|
||||
return join(p[1:mincnt], dlm)
|
||||
end
|
||||
|
||||
test = ["/home/user1/tmp/coverage/test",
|
||||
"/home/user1/tmp/covert/operator",
|
||||
"/home/user1/tmp/coven/members"]
|
||||
test = ["/home/user1/tmp/coverage/test", "/home/user1/tmp/covert/operator", "/home/user1/tmp/coven/members"]
|
||||
|
||||
println("Comparing")
|
||||
for s in test
|
||||
println(" ", s)
|
||||
end
|
||||
println("for their common directory path yields:")
|
||||
println(" ", commonpath(test))
|
||||
println("Comparing:\n - ", join(test, "\n - "))
|
||||
println("for their common directory path yields:\n", commonpath(test))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue