Skip to content

fix buffer interfaces #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/EzXML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ using XML2_jll: libxml2
include("error.jl")
include("node.jl")
include("document.jl")
include("buffer.jl")
include("xpath.jl")
include("streamreader.jl")

Expand Down
32 changes: 0 additions & 32 deletions src/buffer.jl

This file was deleted.

38 changes: 27 additions & 11 deletions src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,37 @@ function prettyprint(io::IO, node::Node)
dump_node(io, node, true)
end

# Dump `node` to `io`.
function dump_node(io, node, format)
function dump_node(io::IO, node::Node, format::Bool)
if hasdocument(node)
doc_ptr = document(node).node.ptr
else
doc_ptr = C_NULL
doc_ptr = convert(Ptr{_Node}, C_NULL)
end
buf_ptr = @check ccall(
(:xmlBufCreate, libxml2),
Ptr{Cvoid},
()) != C_NULL
try
level = 0
size = ccall(
(:xmlBufNodeDump, libxml2),
Csize_t,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Cint, Cint),
buf_ptr, doc_ptr, node.ptr, level, format)
content_ptr = @check ccall(
(:xmlBufContent, libxml2),
Ptr{UInt8},
(Ptr{Cvoid},),
buf_ptr) != C_NULL
unsafe_write(io, content_ptr, size)
return nothing
finally
ccall(
(:xmlBufFree, libxml2),
Cvoid,
(Ptr{Cvoid},),
buf_ptr)
end
buf = Buffer()
level = 0
len = @check ccall(
(:xmlNodeDump, libxml2),
Cint,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Cint, Cint),
buf.ptr, doc_ptr, node.ptr, level, format) != -1
print(io, unsafe_string(unsafe_load(buf.ptr).content))
end

function Base.:(==)(n1::Node, n2::Node)
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1327,15 +1327,15 @@ end

doc = parsexml("<e1><e2/></e1>")
buf = IOBuffer()
print(buf, doc)
@test print(buf, doc) === nothing
@test take!(buf) == b"""
<?xml version="1.0" encoding="UTF-8"?>
<e1><e2/></e1>
"""

doc = parsexml("<e1><e2/></e1>")
buf = IOBuffer()
prettyprint(buf, doc)
@test prettyprint(buf, doc) === nothing
@test take!(buf) == b"""
<?xml version="1.0" encoding="UTF-8"?>
<e1>
Expand Down