Skip to content

Commit ff9850d

Browse files
authored
replace searchindex (#41)
1 parent d25b9a7 commit ff9850d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/node.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ end
10801080
# ----------
10811081

10821082
function Base.getindex(node::Node, attr::AbstractString)
1083-
i = searchindex(attr, ':')
1083+
i = findfirstchar(':', attr)
10841084
if i == 0
10851085
str_ptr = ccall(
10861086
(:xmlGetNoNsProp, libxml2),
@@ -1109,7 +1109,7 @@ function Base.getindex(node::Node, attr::AbstractString)
11091109
end
11101110

11111111
function Base.haskey(node::Node, attr::AbstractString)
1112-
i = searchindex(attr, ':')
1112+
i = findfirstchar(':', attr)
11131113
if i == 0
11141114
prop_ptr = ccall(
11151115
(:xmlHasNsProp, libxml2),
@@ -1143,7 +1143,7 @@ function Base.setindex!(node::Node, val, attr::AbstractString)
11431143
end
11441144

11451145
function Base.delete!(node::Node, attr::AbstractString)
1146-
i = searchindex(attr, ':')
1146+
i = findfirstchar(':', attr)
11471147
if i == 0
11481148
# This function handles attributes in no namespace.
11491149
ccall(
@@ -1165,6 +1165,14 @@ function Base.delete!(node::Node, attr::AbstractString)
11651165
return node
11661166
end
11671167

1168+
function findfirstchar(char::Char, str::AbstractString)
1169+
@static if VERSION > v"0.7-"
1170+
return first(findfirst(equalto(char), str))
1171+
else
1172+
return searchindex(str, char)
1173+
end
1174+
end
1175+
11681176

11691177
# Namespaces
11701178
# ----------

0 commit comments

Comments
 (0)