XPath: Fixed following and preceding axes
git-svn-id: http://pugixml.googlecode.com/svn/trunk@203 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
c0ce7ab70e
commit
0092960c9e
1 changed files with 29 additions and 15 deletions
|
@ -170,6 +170,13 @@ namespace
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool node_is_ancestor(xml_node parent, xml_node node)
|
||||
{
|
||||
while (node && node != parent) node = node.parent();
|
||||
|
||||
return parent && node == parent;
|
||||
}
|
||||
|
||||
struct document_order_comparator
|
||||
{
|
||||
|
@ -1605,21 +1612,28 @@ namespace pugi
|
|||
|
||||
xml_node cur = n;
|
||||
|
||||
for (;;)
|
||||
// exit from this node so that we don't include descendants
|
||||
while (cur && !cur.next_sibling()) cur = cur.parent();
|
||||
cur = cur.next_sibling();
|
||||
|
||||
if (cur)
|
||||
{
|
||||
if (cur.first_child())
|
||||
cur = cur.first_child();
|
||||
else if (cur.next_sibling())
|
||||
cur = cur.next_sibling();
|
||||
else
|
||||
for (;;)
|
||||
{
|
||||
while (cur && !cur.next_sibling()) cur = cur.parent();
|
||||
cur = cur.next_sibling();
|
||||
|
||||
if (!cur) break;
|
||||
step_push(ns, cur);
|
||||
|
||||
if (cur.first_child())
|
||||
cur = cur.first_child();
|
||||
else if (cur.next_sibling())
|
||||
cur = cur.next_sibling();
|
||||
else
|
||||
{
|
||||
while (cur && !cur.next_sibling()) cur = cur.parent();
|
||||
cur = cur.next_sibling();
|
||||
|
||||
if (!cur) break;
|
||||
}
|
||||
}
|
||||
|
||||
step_push(ns, cur);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -1642,7 +1656,7 @@ namespace pugi
|
|||
cur = cur.last_child();
|
||||
else
|
||||
{
|
||||
// leaf node
|
||||
// leaf node, can't be ancestor
|
||||
step_push(ns, cur);
|
||||
|
||||
if (cur.previous_sibling())
|
||||
|
@ -1653,8 +1667,8 @@ namespace pugi
|
|||
{
|
||||
cur = cur.parent();
|
||||
if (!cur) break;
|
||||
|
||||
step_push(ns, cur);
|
||||
|
||||
if (!node_is_ancestor(cur, n)) step_push(ns, cur);
|
||||
}
|
||||
while (!cur.previous_sibling());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue