Skip to content

Commit

Permalink
New default separators
Browse files Browse the repository at this point in the history
  • Loading branch information
josePereiro committed Apr 23, 2022
1 parent 79de87f commit 0b9fa67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/parse_dfname.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ end
# end

_noerr(x...) = nothing
function _parse_dfname(name::String, ondigest::Function)
function _parse_dfname(dfn::String, ondigest::Function)
_check__SEPS()

dfn = basename(dfn)

# containers
head = []
params = Dict{String, Any}()
ext = ""

# empty string
isempty(name) && return (;head, params, ext)
isempty(dfn) && return (;head, params, ext)

# escape
ESC_SEPS = _hex_escaped_seps()
Expand All @@ -53,7 +55,7 @@ function _parse_dfname(name::String, ondigest::Function)
hex_extsep = ESC_SEPS[:EXT_SEP] |> Regex

# first digest
dig = split(name, hex_elsep; keepempty = false)
dig = split(dfn, hex_elsep; keepempty = false)

# extenssion
# if "blo<<bla=1>>.ext", extract ".ext"
Expand All @@ -72,16 +74,16 @@ function _parse_dfname(name::String, ondigest::Function)

# redigest
if !isempty(ext)
name = name[1:end - length(ext)]
dig = split(name, hex_elsep; keepempty = false)
dfn = dfn[1:end - length(ext)]
dig = split(dfn, hex_elsep; keepempty = false)
end

# head
for _ in eachindex(dig)
startswith(first(dig), hex_plsep) && break
str = popfirst!(dig)
str = _check_str(str, _noerr)
isnothing(str) && return ondigest(name, dig)
isnothing(str) && return ondigest(dfn, dig)
push!(head, _parse_val(str))
end

Expand All @@ -94,7 +96,7 @@ function _parse_dfname(name::String, ondigest::Function)
end
end

!isempty(dig) && return ondigest(name, dig)
!isempty(dig) && return ondigest(dfn, dig)

return (;head, params, ext)

Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,17 @@ function _run_tests()
let
head = "dat"
ext = ".jls"

fname = dfname(head, ext)
par_head, par_params, par_ext = parse_dfname(fname)
@test head in par_head
@test ext == par_ext

# with dir
fname = dfname([@__DIR__], head, ext)
par_head, par_params, par_ext = parse_dfname(fname)
@test head in par_head
@test ext == par_ext
end

for it in 1:100
Expand Down

0 comments on commit 0b9fa67

Please sign in to comment.