Skip to content

Commit fc58a60

Browse files
committed
some cleanup
1 parent cf8d572 commit fc58a60

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/Manifest.toml
22
*generated_xsd.jl
33
*.xml
4+
*.gz

src/XML.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ end
3434
XMLTokenIterator(io::IO) = XMLTokenIterator(io, position(io), IOBuffer())
3535

3636
readchar(o::XMLTokenIterator) = (c = read(o.io, Char); write(o.buffer, c); c)
37-
reset(o::XMLTokenIterator) = seek(o.io, o.start_pos)
37+
reset(o::XMLTokenIterator) = o.start_pos == 0 ? seekstart(o.io) : seek(o.io, o.start_pos)
3838

3939
function readuntil(o::XMLTokenIterator, char::Char)
4040
c = readchar(o)
@@ -54,9 +54,9 @@ function readuntil(o::XMLTokenIterator, pattern::String)
5454
end
5555

5656
function Base.iterate(o::XMLTokenIterator, state=0)
57-
state == 0 && seek(o.io, o.start_pos)
57+
state == 0 && reset(o)
5858
pair = next_token(o)
59-
isnothing(pair) ? nothing : (pair, state+1)
59+
isnothing(pair) ? nothing : (pair, state + 1)
6060
end
6161

6262
function next_token(o::XMLTokenIterator)
@@ -251,6 +251,7 @@ function Document(o::XMLTokenIterator)
251251
end
252252

253253
Document(file::String) = open(io -> Document(XMLTokenIterator(io)), file, "r")
254+
Document(io::IO) = Document(XMLTokenIterator(io))
254255

255256
Base.show(io::IO, ::MIME"text/plain", o::Document) = print_tree(io, o; maxdepth=1)
256257

0 commit comments

Comments
 (0)