From 1c567deccacf26e93927878b8c294377c4d5a9cf Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sat, 29 May 2010 20:11:36 +0000 Subject: Fixed following:: and preceding:: axes for attribute nodes git-svn-id: http://pugixml.googlecode.com/svn/trunk@466 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixpath.cpp | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pugixpath.cpp b/src/pugixpath.cpp index 2296814..94498bc 100644 --- a/src/pugixpath.cpp +++ b/src/pugixpath.cpp @@ -1725,7 +1725,7 @@ namespace pugi } } - template void step_fill(xpath_node_set& ns, const xml_attribute& a, const xml_node& p, T) + template void step_fill(xpath_node_set& ns, const xml_attribute& a, const xml_node& p, T v) { const axis_t axis = T::axis; @@ -1750,6 +1750,39 @@ namespace pugi break; } + + case axis_following: + { + ns.m_type = ns.empty() ? xpath_node_set::type_sorted : xpath_node_set::type_unsorted; + + xml_node cur = p; + + for (;;) + { + 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; + } + + case axis_preceding: + { + // preceding:: axis does not include attribute nodes and attribute ancestors (they are the same as parent's ancestors), so we can reuse node preceding + step_fill(ns, p, v); + break; + } default: assert(!"Unimplemented axis"); @@ -1760,6 +1793,8 @@ namespace pugi { const axis_t axis = T::axis; + assert(ns.empty()); + switch (axis) { case axis_parent: @@ -1823,6 +1858,8 @@ namespace pugi case axis_ancestor: case axis_ancestor_or_self: + case axis_following: + case axis_preceding: if (m_left) { xpath_node_set s = m_left->eval_node_set(c); @@ -1849,9 +1886,7 @@ namespace pugi break; - case axis_following: case axis_following_sibling: - case axis_preceding: case axis_preceding_sibling: case axis_attribute: case axis_child: -- cgit v1.2.3