Skip to content

Commit 485b650

Browse files
committed
change ordereddict to dict
1 parent 2bdd75d commit 485b650

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: CI
22
on:
33
push:
4-
branches: [main]
4+
branches: [main, dev]
55
tags: ["*"]
66
pull_request:
77
jobs:

Project.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ authors = ["Josh Day <[email protected]> and contributors"]
44
version = "0.1.3"
55

66
[deps]
7-
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
8-
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
97
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
10-
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
118
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
129

1310
[compat]
14-
AbstractTrees = "0.3, 0.4"
15-
OrderedCollections = "1.4"
1611
julia = "1.7"
1712

1813
[extras]

src/XML.jl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module XML
22

3-
using OrderedCollections: OrderedDict
43
using Mmap
54
using Tables
6-
import AbstractTrees: AbstractTrees, children, parent
75

86
export Node, RowNode, Children,
97
children, parent, nodetype, tag, attributes, value, depth, next, prev
@@ -82,7 +80,7 @@ Useful functions:
8280
- next(o::RawData) --> RawData of the next chunk (or `nothing`).
8381
- prev(o::RawData) --> RawData of the previous chunk (or `nothing`).
8482
- tag(o::RawData) --> String of the tag name (or `nothing`).
85-
- attributes(o::RawData) --> OrderedDict{String, String} of the attributes (or `nothing`).
83+
- attributes(o::RawData) --> Dict{String, String} of the attributes (or `nothing`).
8684
- value(o::RawData) --> String of the value (or `nothing`).
8785
- children(o::RawData) --> Vector{RawData} of the children (or `nothing`).
8886
- parent(o::RawData) --> RawData of the parent (or `nothing`)
@@ -100,6 +98,9 @@ RawData(filename::String) = RawData(Mmap.mmap(filename))
10098

10199
parse(x::AbstractString, ::Type{RawData}) = RawData(Vector{UInt8}(x))
102100

101+
# Mostly for debugging
102+
Base.peek(o::RawData, n::Int) = String(@view(o.data[o.pos + o.len + 1:min(end, o.pos + o.len + n + 1)]))
103+
103104
Tables.rows(o::RawData) = o
104105
Tables.schema(o::RawData) = Tables.Schema(fieldnames(RawData)[1:end-1], fieldtypes(RawData)[1:end-1])
105106

@@ -143,7 +144,7 @@ end
143144
function get_attributes(data, i, j)
144145
i = name_start(data, i)
145146
i > j && return nothing
146-
out = OrderedDict{String, String}()
147+
out = Dict{String, String}()
147148
while !isnothing(i) && i < j
148149
key, i = get_name(data, i)
149150
# get quotechar the value is wrapped in (either ' or ")
@@ -177,7 +178,7 @@ function tag(o::RawData)
177178
end
178179

179180
"""
180-
attributes(node) --> OrderedDict{String, String} or Nothing
181+
attributes(node) --> Dict{String, String} or Nothing
181182
182183
Return the attributes of `ELEMENT`, `DECLARATION`, or `PROCESSING_INSTRUCTION` nodes.
183184
"""
@@ -387,7 +388,7 @@ a tabular dataset, e.g.
387388
struct RowNode
388389
nodetype::NodeType
389390
tag::Union{String, Nothing}
390-
attributes::Union{OrderedDict{String, String}, Nothing}
391+
attributes::Union{Dict{String, String}, Nothing}
391392
value::Union{String, Nothing}
392393
data::RawData
393394
end
@@ -416,7 +417,7 @@ Base.propertynames(o::RowNode) = (:depth, :nodetype, :tag, :attributes, :value)
416417
Tables.rows(o::RowNode) = o
417418
Tables.schema(o::RowNode) = Tables.Schema(
418419
(:depth, :nodetype, :tag, :attributes, :value),
419-
(Int, NodeType, Union{Nothing, String}, Union{Nothing, OrderedDict{String, String}}, Union{Nothing, String}),
420+
(Int, NodeType, Union{Nothing, String}, Union{Nothing, Dict{String, String}}, Union{Nothing, String}),
420421
)
421422

422423
children(o::RowNode) = RowNode.(children(getfield(o, :data)))
@@ -456,7 +457,7 @@ end
456457
struct FastNode
457458
nodetype::NodeType
458459
tag::Union{Nothing, String}
459-
attributes::Union{Nothing, OrderedDict{String, String}}
460+
attributes::Union{Nothing, Dict{String, String}}
460461
value::Union{Nothing, String}
461462
children::Union{Nothing, Vector{FastNode}}
462463
depth::Int
@@ -483,7 +484,7 @@ Base.lastindex(o::FastNode) = length(o.children)
483484
Base.@kwdef struct Node
484485
nodetype::NodeType
485486
tag::Union{Nothing, String} = nothing
486-
attributes::Union{Nothing, OrderedDict{String, String}} = nothing
487+
attributes::Union{Nothing, Dict{String, String}} = nothing
487488
value::Union{Nothing, String} = nothing
488489
children::Union{Nothing, Vector{Node}} = nothing
489490
depth::Int = -1
@@ -544,12 +545,12 @@ _node(x::Node; depth=x.depth) = Node(x; depth)
544545

545546
module NodeConstructors
546547
import .._node
547-
import ..Node, ..OrderedDict
548+
import ..Node, ..Dict
548549
import ..TEXT, ..DOCUMENT, ..DTD, ..DECLARATION, ..PROCESSING_INSTRUCTION, ..COMMENT, ..CDATA, ..ELEMENT
549550

550551
export document, dtd, declaration, processing_instruction, comment, cdata, text, element
551552

552-
attrs(kw) = OrderedDict{String,String}(string(k) => string(v) for (k,v) in kw)
553+
attrs(kw) = Dict{String,String}(string(k) => string(v) for (k,v) in kw)
553554

554555
"""
555556
document(children::Vector{Node})
@@ -566,13 +567,13 @@ dtd(value::AbstractString) = Node(nodetype=DTD, value=String(value))
566567
"""
567568
declaration(; attributes...)
568569
"""
569-
declaration(attributes::OrderedDict{String,String}) = Node(;nodetype=DECLARATION, attributes)
570+
declaration(attributes::Dict{String,String}) = Node(;nodetype=DECLARATION, attributes)
570571
declaration(; kw...) = declaration(attrs(kw))
571572

572573
"""
573574
processing_instruction(tag::AbstractString; attributes...)
574575
"""
575-
processing_instruction(tag, attributes::OrderedDict{String,String}) = Node(;nodetype=PROCESSING_INSTRUCTION, tag=string(tag), attributes)
576+
processing_instruction(tag, attributes::Dict{String,String}) = Node(;nodetype=PROCESSING_INSTRUCTION, tag=string(tag), attributes)
576577
processing_instruction(tag; kw...) = processing_instruction(tag, attrs(kw))
577578

578579
"""
@@ -786,7 +787,7 @@ function write(io::IO, x; indent = " ")
786787
elseif nodetype === CDATA
787788
print(io, "<![CDATA[", value, "]]>")
788789
elseif nodetype === DOCUMENT
789-
foreach(AbstractTrees.children(x)) do child
790+
foreach(children) do child
790791
write(io, child; indent)
791792
println(io)
792793
end

test/runtests.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using XML
22
using Downloads: download
33
using Test
4-
using OrderedCollections
54

65
#-----------------------------------------------------------------------------# files
76
xml_spec = download("http://www.w3.org/2001/xml.xsd")
@@ -28,13 +27,13 @@ all_files = [
2827
(xml = "<?xml version=\"1.0\" key=\"value\"?>",
2928
nodetype = XML.DECLARATION,
3029
tag=nothing,
31-
attributes=OrderedDict("version" => "1.0", "key" => "value"),
30+
attributes=Dict("version" => "1.0", "key" => "value"),
3231
value=nothing),
3332

3433
(xml = "<tag _id=\"1\", x=\"abc\" />",
3534
nodetype = XML.ELEMENT,
3635
tag="tag",
37-
attributes=OrderedDict("_id" => "1", "x" => "abc"),
36+
attributes=Dict("_id" => "1", "x" => "abc"),
3837
value=nothing),
3938
(xml = "<!-- comment -->",
4039
nodetype = XML.COMMENT,
@@ -102,7 +101,7 @@ end
102101
@testset "tag/attributes/value" begin
103102
x = doc[1] # <?xml version="1.0"?>
104103
@test XML.tag(x) === nothing
105-
@test XML.attributes(x) == OrderedDict("version" => "1.0")
104+
@test XML.attributes(x) == Dict("version" => "1.0")
106105
@test XML.value(x) === nothing
107106

108107
x = XML.next(x) # <catalog>
@@ -112,7 +111,7 @@ end
112111

113112
x = XML.next(x) # <book id="bk101">
114113
@test XML.tag(x) == "book"
115-
@test XML.attributes(x) == OrderedDict("id" => "bk101")
114+
@test XML.attributes(x) == Dict("id" => "bk101")
116115
@test XML.value(x) === nothing
117116

118117
x = XML.next(x) # <author>

0 commit comments

Comments
 (0)