Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.5 Strings #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
32 changes: 16 additions & 16 deletions src/TOML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ include("datetime.jl")


type ParserState
subject::UTF8String
subject::(@compat String)
index::Integer
line::Integer
result::Dict{UTF8String, Any}
cur_tbl::Dict{UTF8String, Any}
tbl_names::Set{UTF8String}
result::Dict{(@compat String), Any}
cur_tbl::Dict{(@compat String), Any}
tbl_names::Set{(@compat String)}

function ParserState{T<: @compat Union{AbstractString, Array{UInt8, 1}}}(subject::T)
if isa(subject, @compat Union{ByteString, Array{UInt8, 1}}) && !isvalid(UTF8String, subject)
if isa(subject, @compat Union{ByteString, Array{UInt8, 1}}) && !isvalid((@compat String), subject)
throw(TOMLError("$T with invalid UTF-8 byte sequence."))
end
try
subject = convert(UTF8String, subject)
subject = convert((@compat String), subject)
catch
throw(TOMLError("Couldn't convert $T to UTF8String " *
"(no method convert(Type{UTF8String}, $T))."))
throw(TOMLError("Couldn't convert $T to (@compat String) " *
"(no method convert(Type{(@compat String)}, $T))."))
end
BOM = length(subject) > 0 && subject[1] == '\ufeff' ? true : false
maintbl = Dict{UTF8String,Any}()
maintbl = Dict{(@compat String),Any}()
new(
subject,
BOM ? 4 : 1, # index. Strip the BOM if present.
1, # line
maintbl, # result
maintbl, # cur_tbl
Set{UTF8String}() # tbl_names
Set{(@compat String)}() # tbl_names
)
end
end
Expand Down Expand Up @@ -102,7 +102,7 @@ function table(state::ParserState)
_error("Key \"$k\" already defined", state)
end
else
tbl[k] = Dict{UTF8String,Any}()
tbl[k] = Dict{(@compat String),Any}()
tbl = tbl[k]
end
end
Expand All @@ -129,7 +129,7 @@ function table_array(state::ParserState)
end
if haskey(tbl, k)
if i < length(keys)
if !isa(tbl[k], @compat Union{Array{Dict{UTF8String, Any}, 1}, Dict{UTF8String, Any}})
if !isa(tbl[k], @compat Union{Array{Dict{(@compat String), Any}, 1}, Dict{(@compat String), Any}})
_error("Attempt to overwrite key $(join(keys[1:i], '.'))", state)
end
if isa(tbl[k], Dict)
Expand All @@ -138,19 +138,19 @@ function table_array(state::ParserState)
tbl = last(tbl[k])
end
else
if !isa(tbl[k], Array{Dict{UTF8String, Any}, 1})
if !isa(tbl[k], Array{Dict{(@compat String), Any}, 1})
_error("Attempt to overwrite value with array", state)
end
push!(tbl[k], Dict{UTF8String,Any}())
push!(tbl[k], Dict{(@compat String),Any}())
tbl = last(tbl[k])
break
end
else
if i < length(keys)
tbl[k] = Dict{UTF8String,Any}()
tbl[k] = Dict{(@compat String),Any}()
tbl = tbl[k]
else # we're done
tbl[k] = [Dict{UTF8String,Any}()]
tbl[k] = [Dict{(@compat String),Any}()]
tbl = last(tbl[k])
break
end
Expand Down