@@ -126,28 +126,9 @@ is_node(o::RawData) = o.type !== RAW_ELEMENT_CLOSE
126
126
nodes (o:: RawData ) = Iterators. Filter (is_node, o)
127
127
128
128
# -----------------------------------------------------------------------------# 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
-
145
129
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
148
130
is_name_char (x:: UInt8 ) = is_name_start_char (x) || x in UInt8 (' 0' ): UInt8 (' 9' ) || x == UInt8 (' -' ) || x == UInt8 (' .' )
149
131
150
- # find the start/stop of a name given a starting position `i`
151
132
name_start (data, i) = findnext (is_name_start_char, data, i)
152
133
name_stop (data, i) = findnext (! is_name_char, data, i) - 1
153
134
@@ -159,15 +140,14 @@ end
159
140
160
141
# -----------------------------------------------------------------------------# get_attributes
161
142
# 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)
164
144
i = name_start (data, i)
165
145
i > j && return nothing
166
146
out = OrderedDict {String, String} ()
167
147
while ! isnothing (i) && i < j
168
148
key, i = get_name (data, i)
169
149
# 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 )
171
151
quotechar = data[i]
172
152
i2 = findnext (== (quotechar), data, i + 1 )
173
153
@views value = String (data[i+ 1 : i2- 1 ])
@@ -206,9 +186,9 @@ function attributes(o::RawData)
206
186
i = o. pos
207
187
i = name_start (o. data, i)
208
188
i = name_stop (o. data, i)
209
- get_attributes (o. data, i + 1 )
189
+ get_attributes (o. data, i + 1 , o . pos + o . len )
210
190
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 )
212
192
else
213
193
nothing
214
194
end
0 commit comments