summaryrefslogtreecommitdiff
path: root/src/domhelpers.cpp
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-07-24 22:32:14 +0000
committerStef Walter <stef@memberwebs.com>2004-07-24 22:32:14 +0000
commita70bc0519f2705257efca1c8a714a44c941534fb (patch)
treef43dd57982917760b8d12534e5a3c9520da8f024 /src/domhelpers.cpp
parent07e7c437647e45b6f06b30a8dc02b663fd6a782c (diff)
- Bug fixes to new fixup scheme
Diffstat (limited to 'src/domhelpers.cpp')
-rw-r--r--src/domhelpers.cpp103
1 files changed, 72 insertions, 31 deletions
diff --git a/src/domhelpers.cpp b/src/domhelpers.cpp
index ac93f10..7ecf963 100644
--- a/src/domhelpers.cpp
+++ b/src/domhelpers.cpp
@@ -186,6 +186,8 @@ DOM::Element DOMHelpers::getChildElement(const DOM::Node& parent, const string&
{
if(isElement(child, name))
return (DOM::Element&)child;
+
+ child = child.getNextSibling();
}
return DOM::Element();
@@ -226,6 +228,8 @@ void ElementTable::load(const DOM::Node& parent, const string& name)
if(!id.empty())
insert(make_pair(id, el));
}
+
+ child = child.getNextSibling();
}
}
@@ -250,30 +254,55 @@ void ElementTable::removeIds()
void ElementIterator::next()
{
- if(m_current == NULL)
- return;
+ if(m_flags == AFTER_LAST)
+ return;
+
+ if(m_flags == BEFORE_FIRST)
+ m_current = m_top;
+
+ ASSERT(m_current != NULL);
DOM::Node n;
// Always descend into children first
if(m_current.hasChildNodes())
{
- m_current = nextel(m_current.getFirstChild());
- if(m_current != NULL)
+ n = nextel(m_current.getFirstChild());
+ if(n != NULL)
+ {
+ m_current = n;
+ m_flags = ITERATING;
return;
+ }
}
// Look for siblings along the current level
- m_current = nextel(m_current.getNextSibling());
- if(m_current != NULL)
+ n = nextel(m_current.getNextSibling());
+ if(n != NULL)
+ {
+ m_current = n;
+ m_flags = ITERATING;
return;
-
- // Go back up to parent
- m_current = m_current.getParentNode();
-
- // But check top against parent
- if(m_current == NULL || m_current == m_top)
- m_current = NULL;
+ }
+
+ for(;;)
+ {
+ // Go back up to parent, and get it's next sibling
+ m_current = m_current.getParentNode();
+ if(m_current == NULL || m_current == m_top)
+ break;
+
+ n = nextel(m_current.getNextSibling());
+ if(n != NULL)
+ {
+ m_current = n;
+ m_flags = ITERATING;
+ return;
+ }
+ }
+
+ m_flags = AFTER_LAST;
+ m_current = NULL;
}
DOM::Element ElementIterator::nextel(DOM::Node node)
@@ -291,29 +320,41 @@ DOM::Element ElementIterator::nextel(DOM::Node node)
void ElementIterator::prev()
{
- /* Allow backing into the iterator */
- if(m_current == NULL)
- m_current = m_top;
+ if(m_flags == BEFORE_FIRST)
+ return;
DOM::Node n;
- // Always descend into children first
- if(m_current.hasChildNodes())
- {
- m_current = prevel(m_current.getLastChild());
- if(m_current != NULL)
- return;
- }
+ if(m_flags == AFTER_LAST)
+ n = m_top;
+ else
+ n = prevel(m_current.getPreviousSibling());
+
+ while(n != NULL)
+ {
+ m_current = n;
+
+ n = n.hasChildNodes() ?
+ prevel(m_current.getLastChild()) : DOM::Node();
+
+ if(n == NULL)
+ {
+ m_flags = ITERATING;
+ return;
+ }
+ }
+
+ // Go back up to parent
+ m_current = m_current.getParentNode();
+
+ if(m_current == NULL || m_current == m_top)
+ {
+ m_flags = BEFORE_FIRST;
+ m_current = NULL;
+ return;
+ }
- // Look for siblings along the current level
- m_current = prevel(m_current.getPreviousSibling());
- if(m_current != NULL)
- return;
- // Go back up to parent
- DOM::Node parent = m_current.getParentNode();
- if(parent != m_top)
- m_current = (DOM::Element&)parent;
}