Skip to content

Commit 2bdd75d

Browse files
committed
cleanup
1 parent b947074 commit 2bdd75d

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

src/XML.jl

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,9 @@ is_node(o::RawData) = o.type !== RAW_ELEMENT_CLOSE
126126
nodes(o::RawData) = Iterators.Filter(is_node, o)
127127

128128
#-----------------------------------------------------------------------------# get_name
129-
# # find the start/stop of a name given a starting position `i`
130-
# _name_start(data, i) = findnext(x -> isletter(Char(x)) || Char(x) === '_', data, i)
131-
# is_name_char(x) = (c = Char(x); isletter(c) || isdigit(c) || c ∈ "._-:")
132-
# function _name_stop(data, i)
133-
# i = findnext(!is_name_char, data, i)
134-
# isnothing(i) ? length(data) : i
135-
# end
136-
137-
# # starting at position i, return name and position after name
138-
# function get_name(data, i)
139-
# i = _name_start(data, i)
140-
# j = _name_stop(data, i)
141-
# @views name = String(data[i:j-1])
142-
# return name, j
143-
# end
144-
145129
is_name_start_char(x::UInt8) = x in UInt8('A'):UInt8('Z') || x in UInt8('a'):UInt8('z') || x == UInt8('_')
146-
147-
# Character is letter, underscore, digit, hyphen, or period
148130
is_name_char(x::UInt8) = is_name_start_char(x) || x in UInt8('0'):UInt8('9') || x == UInt8('-') || x == UInt8('.')
149131

150-
# find the start/stop of a name given a starting position `i`
151132
name_start(data, i) = findnext(is_name_start_char, data, i)
152133
name_stop(data, i) = findnext(!is_name_char, data, i) - 1
153134

@@ -159,15 +140,14 @@ end
159140

160141
#-----------------------------------------------------------------------------# get_attributes
161142
# starting at position i, return attributes up until the next '>' or '?' (DTD)
162-
function get_attributes(data, i)
163-
j = findnext(x -> x == UInt8('>') || x == UInt8('?'), data, i)
143+
function get_attributes(data, i, j)
164144
i = name_start(data, i)
165145
i > j && return nothing
166146
out = OrderedDict{String, String}()
167147
while !isnothing(i) && i < j
168148
key, i = get_name(data, i)
169149
# get quotechar the value is wrapped in (either ' or ")
170-
i = findnext(x -> Char(x) === '"' || Char(x) === ''', data, i + 1)
150+
i = findnext(x -> x === UInt8('"') || x === UInt8('''), data, i + 1)
171151
quotechar = data[i]
172152
i2 = findnext(==(quotechar), data, i + 1)
173153
@views value = String(data[i+1:i2-1])
@@ -206,9 +186,9 @@ function attributes(o::RawData)
206186
i = o.pos
207187
i = name_start(o.data, i)
208188
i = name_stop(o.data, i)
209-
get_attributes(o.data, i + 1)
189+
get_attributes(o.data, i + 1, o.pos + o.len)
210190
elseif o.type === RAW_DECLARATION
211-
get_attributes(o.data, o.pos + 6)
191+
get_attributes(o.data, o.pos + 6, o.pos + o.len)
212192
else
213193
nothing
214194
end

0 commit comments

Comments
 (0)