0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-27 13:33:17 +08:00

Added offset_debug

git-svn-id: http://pugixml.googlecode.com/svn/trunk@108 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
arseny.kapoulkine 2009-01-18 11:44:57 +00:00
parent 9bc19368f2
commit f57ab52894
2 changed files with 45 additions and 1 deletions

View File

@ -203,11 +203,12 @@ namespace pugi
struct xml_document_struct: public xml_node_struct
{
xml_document_struct(): xml_node_struct(node_document), allocator(0)
xml_document_struct(): xml_node_struct(node_document), allocator(0), buffer(0)
{
}
xml_allocator allocator;
const char* buffer;
};
xml_document_struct* xml_allocator::allocate_document()
@ -2620,6 +2621,36 @@ namespace pugi
node_output(buffered_writer, *this, indent, flags, depth);
}
int xml_node::offset_debug() const
{
xml_node_struct* r = root()._root;
if (!r) return -1;
const char* buffer = static_cast<xml_document_struct*>(r)->buffer;
if (!buffer) return -1;
switch (type())
{
case node_document:
return 0;
case node_element:
case node_declaration:
return _root->name_insitu ? _root->name - buffer : -1;
case node_pcdata:
case node_cdata:
case node_comment:
case node_pi:
return _root->value_insitu ? _root->value - buffer : -1;
default:
return -1;
}
}
#ifdef __BORLANDC__
bool operator&&(const xml_node& lhs, bool rhs)
{
@ -2891,6 +2922,9 @@ namespace pugi
{
destroy();
// for offset_debug
static_cast<xml_document_struct*>(_root)->buffer = xmlstr;
xml_allocator& alloc = static_cast<xml_document_struct*>(_root)->allocator;
xml_parser parser(alloc);

View File

@ -1210,6 +1210,16 @@ namespace pugi
* \param depth - starting depth (used for indentation)
*/
void print(xml_writer& writer, const char* indent = "\t", unsigned int flags = format_default, unsigned int depth = 0);
/**
* Get node offset in parsed file/string (in bytes) for debugging purposes
*
* \return offset in bytes to start of node data, or -1 in case of error
* \note This will return -1 if node information changed to the extent that it's no longer possible to calculate offset, for example
* if element node name has significantly changed; this is guaranteed to return correct offset only for nodes that have not changed
* since parsing.
*/
int offset_debug() const;
};
#ifdef __BORLANDC__