Skip to content

Commit a50653c

Browse files
committed
Merge pull request #2 from paulogeyer/master
using String instead of ASCIIString
2 parents 87e6762 + 6d376ba commit a50653c

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/document.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,30 @@ function set_root(xdoc::XMLDocument, xroot::XMLElement)
7676
ccall(xmlDocSetRootElement, Xptr, (Xptr, Xptr), xdoc.ptr, xroot.node.ptr)
7777
end
7878

79-
function create_root(xdoc::XMLDocument, name::ASCIIString)
79+
function create_root(xdoc::XMLDocument, name::String)
8080
xroot = new_element(name)
8181
set_root(xdoc, xroot)
8282
return xroot
8383
end
8484

8585
#### parse and free
8686

87-
function parse_file(filename::ASCIIString)
87+
function parse_file(filename::String)
8888
p = ccall(xmlParseFile, Xptr, (Ptr{Cchar},), filename)
8989
p != nullptr || throw(XMLParseError("Failure in parsing an XML file."))
9090
XMLDocument(p)
9191
end
9292

93-
function parse_string(s::ASCIIString)
94-
p = ccall(xmlParseMemory, Xptr, (Ptr{Cchar}, Cint), s, length(s) + 1)
93+
function parse_string(s::String)
94+
p = ccall(xmlParseMemory, Xptr, (Ptr{Cchar}, Cint), s, sizeof(s) + 1)
9595
p != nullptr || throw(XMLParseError("Failure in parsing an XML string."))
9696
XMLDocument(p)
9797
end
9898

9999

100100
#### output
101101

102-
function save_file(xdoc::XMLDocument, filename::ASCIIString; encoding::ASCIIString="utf-8")
102+
function save_file(xdoc::XMLDocument, filename::String; encoding::String="utf-8")
103103
ret = ccall(xmlSaveFormatFileEnc, Cint, (Ptr{Cchar}, Xptr, Ptr{Cchar}, Cint),
104104
filename, xdoc.ptr, encoding, 1)
105105
if ret < 0
@@ -108,7 +108,7 @@ function save_file(xdoc::XMLDocument, filename::ASCIIString; encoding::ASCIIStri
108108
return int(ret) # number of bytes written
109109
end
110110

111-
function Base.string(xdoc::XMLDocument; encoding::ASCIIString="utf-8")
111+
function Base.string(xdoc::XMLDocument; encoding::String="utf-8")
112112
buf_out = Array(Xstr, 1)
113113
len_out = Array(Cint, 1)
114114
ccall(xmlDocDumpFormatMemoryEnc, Void, (Xptr, Ptr{Xstr}, Ptr{Cint}, Ptr{Cchar}, Cint),

src/errors.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
abstract XMLError
33

44
immutable XMLParseError <: XMLError
5-
msg::ASCIIString
5+
msg::String
66
end
77

88
immutable XMLNoRootError <: XMLError
@@ -12,11 +12,11 @@ immutable XMLAttributeNotFound <: XMLError
1212
end
1313

1414
immutable XMLWriteError <: XMLError
15-
msg::ASCIIString
15+
msg::String
1616
end
1717

1818
immutable XMLTreeError <: XMLError
19-
msg::ASCIIString
19+
msg::String
2020
end
2121

2222
const dom_exception_causes = [
@@ -35,7 +35,7 @@ const dom_exception_causes = [
3535

3636
immutable DOMException <: XMLError
3737
code::Int
38-
cause::ASCIIString
38+
cause::String
3939

4040
DOMException(code::Int) = new(code, dom_exception_causes[code])
4141
end

src/nodes.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ name(a::XMLAttr) = bytestring(a._struct.name)
8686

8787
function value(a::XMLAttr)
8888
pct = ccall(xmlNodeGetContent, Xstr, (Xptr,), a._struct.children)
89-
(pct != nullptr ? _xcopystr(pct) : "")::ASCIIString
89+
(pct != nullptr ? _xcopystr(pct) : "")::String
9090
end
9191

9292
# iterations
@@ -160,7 +160,7 @@ child_nodes(nd::XMLNode) = XMLNodeIter(nd._struct.children)
160160

161161
function content(nd::XMLNode)
162162
pct = ccall(xmlNodeGetContent, Xstr, (Xptr,), nd.ptr)
163-
(pct != nullptr ? _xcopystr(pct) : "")::ASCIIString
163+
(pct != nullptr ? _xcopystr(pct) : "")::String
164164
end
165165

166166
# dumping
@@ -211,7 +211,7 @@ Base.show(io::IO, x::XMLElement) = Base.show(x.node)
211211

212212
# attribute access
213213

214-
function attribute(x::XMLElement, name::ASCIIString; required::Bool=false)
214+
function attribute(x::XMLElement, name::String; required::Bool=false)
215215
pv = ccall(xmlGetProp, Xstr, (Xptr, Xstr), x.node.ptr, name)
216216
if pv != nullptr
217217
return _xcopystr(pv)
@@ -224,7 +224,7 @@ function attribute(x::XMLElement, name::ASCIIString; required::Bool=false)
224224
end
225225
end
226226

227-
function has_attribute(x::XMLElement, name::ASCIIString)
227+
function has_attribute(x::XMLElement, name::String)
228228
p = ccall(xmlHasProp, Xptr, (Xptr, Xstr), x.node.ptr, name)
229229
return p != nullptr
230230
end
@@ -235,7 +235,7 @@ attributes(x::XMLElement) = XMLAttrIter(x.node._struct.attrs)
235235
function attributes_dict(x::XMLElement)
236236
# make an dictionary based on attributes
237237

238-
dct = (ASCIIString=>ASCIIString)[]
238+
dct = (String=>String)[]
239239
if has_attributes(x)
240240
for a in attributes(x)
241241
dct[name(a)] = value(a)
@@ -259,7 +259,7 @@ child_elements(x::XMLElement) = XMLElementIter(x.node.ptr)
259259

260260
# elements by tag name
261261

262-
function find_element(x::XMLElement, n::ASCIIString)
262+
function find_element(x::XMLElement, n::String)
263263
for c in child_elements(x)
264264
if name(c) == n
265265
return c
@@ -268,7 +268,7 @@ function find_element(x::XMLElement, n::ASCIIString)
268268
return nothing
269269
end
270270

271-
function get_elements_by_tagname(x::XMLElement, n::ASCIIString)
271+
function get_elements_by_tagname(x::XMLElement, n::String)
272272
lst = Array(XMLElement, 0)
273273
for c in child_elements(x)
274274
if name(c) == n
@@ -285,7 +285,7 @@ end
285285
#
286286
#######################################
287287

288-
function new_element(name::ASCIIString)
288+
function new_element(name::String)
289289
p = ccall(xmlNewNode, Xptr, (Xptr, Xstr), nullptr, name)
290290
XMLElement(p)
291291
end
@@ -297,25 +297,25 @@ end
297297

298298
add_child(xparent::XMLElement, xchild::XMLElement) = add_child(xparent, xchild.node)
299299

300-
function new_child(xparent::XMLElement, name::ASCIIString)
300+
function new_child(xparent::XMLElement, name::String)
301301
xc = new_element(name)
302302
add_child(xparent, xc)
303303
return xc
304304
end
305305

306-
function new_textnode(txt::ASCIIString)
306+
function new_textnode(txt::String)
307307
p = ccall(xmlNewText, Xptr, (Xstr,), txt)
308308
XMLNode(p)
309309
end
310310

311-
add_text(x::XMLElement, txt::ASCIIString) = add_child(x, new_textnode(txt))
311+
add_text(x::XMLElement, txt::String) = add_child(x, new_textnode(txt))
312312

313-
function set_attribute(x::XMLElement, name::ASCIIString, val::ASCIIString)
313+
function set_attribute(x::XMLElement, name::String, val::String)
314314
a = ccall(xmlSetProp, Xptr, (Xptr, Xstr, Xstr), x.node.ptr, name, val)
315315
return XMLAttr(a)
316316
end
317317

318-
set_attribute(x::XMLElement, name::ASCIIString, val) = set_attribute(x, name, string(val))
318+
set_attribute(x::XMLElement, name::String, val) = set_attribute(x, name, string(val))
319319

320320
function set_attributes{P<:NTuple{2}}(x::XMLElement, attrs::AbstractArray{P})
321321
for (nam, val) in attrs

0 commit comments

Comments
 (0)