OSDN Git Service

Initial commit
[wordring-tm/wordring-tm.git] / third_party / tidy-html5-master / experimental / TidyNodeIter.c
1 #include "platform.h"
2 #include "tidy-int.h"
3
4 #include "TidyNodeIter.h"
5
6 TidyNodeIter *newTidyNodeIter( Node *pStart )
7 {
8     TidyNodeIter *pThis = NULL;
9     if (NULL != (pThis = MemAlloc( sizeof( TidyNodeIter ))))
10     {
11         ClearMemory( pThis, sizeof( TidyNodeIter ));
12         pThis->pTop = pStart;
13     }
14     return pThis;
15 }
16
17 Node *nextTidyNode( TidyNodeIter *pThis )
18 {
19     if (NULL == pThis->pCurrent)
20     {
21         // just starting out, initialize
22         pThis->pCurrent = pThis->pTop->content;
23     }
24     else if (NULL != pThis->pCurrent->content)
25     {
26         // the next element, if any, is my first-born child
27         pThis->pCurrent = pThis->pCurrent->content;
28     }
29     else 
30     {
31         // no children, I guess my next younger brother inherits the throne.
32         while (   NULL == pThis->pCurrent->next
33                && pThis->pTop != pThis->pCurrent->parent )
34         {
35             //  no siblings, do any of my ancestors have younger sibs?
36             pThis->pCurrent = pThis->pCurrent->parent;
37         }
38         pThis->pCurrent = pThis->pCurrent->next;
39     }
40     return pThis->pCurrent;
41 }
42
43 void setCurrentNode( TidyNodeIter *pThis, Node *newCurr )
44 {
45     if (NULL != newCurr)
46         pThis->pCurrent = newCurr;
47 }