JuliaIO / ConfParser.jl

Julia package for parsing configuration files
Other
44 stars 17 forks source link

Whitespaces in INI files #30

Open tencnivel opened 5 years ago

tencnivel commented 5 years ago

I don't understand why Issue #12 was closed.

Why can't we just strip the values as in the following? It seems to work fine even with comma separated values

function ConfParser.parse_line(line::String)
    parsed   = String[]
    splitted = split(line, ",")
    for raw = splitted
        if occursin(r"\S+", raw)
            clean = strip(raw)
            push!(parsed, clean)
        end
    end
    parsed
end 
grhartl commented 3 years ago

Also stumbled upon this, for me unexpected, behavior, especially since loading and saving the conf again introduces silent data loss (everything behind a whitespace w/o comma)

jonathanBieler commented 3 years ago

@grhartl Indeed that's not great. I'm not too sure what's the intention was here :

https://github.com/JuliaIO/ConfParser.jl/blob/master/src/ConfParser.jl#L95

My guess was to split values by comma (not sure if that's in the ini specs) and filter out possibly resulting whitespace values.

e.g.

foo = 1,2 -> [1,2] foo = 1, ,3 -> [1,3]

I would maybe just remove that whitespace cleaning part, what do you think ?

grhartl commented 3 years ago

Thanks for the fast response. As far as i know there are no offical, uniform ini specs.

Imo moving filtering to the user makes those case more work for the user, but would solve this issue. I would lean towards parsing and saving as literal as possible .As another example, someone may (even if rather brittle) want to index a specific element by position? From my perspective, I would consider the data loss a bug, while the parsing of ", ," is a design choice up to you.