File: TidyNodeIter.c

package info (click to toggle)
tidy-html5 2%3A5.6.0-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 5,512 kB
  • sloc: ansic: 40,477; ruby: 841; sh: 293; makefile: 30; cpp: 30
file content (47 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "tidyplatform.h"
#include "tidy-int.h"

#include "TidyNodeIter.h"

TidyNodeIter *newTidyNodeIter( Node *pStart )
{
    TidyNodeIter *pThis = NULL;
    if (NULL != (pThis = MemAlloc( sizeof( TidyNodeIter ))))
    {
        ClearMemory( pThis, sizeof( TidyNodeIter ));
        pThis->pTop = pStart;
    }
    return pThis;
}

Node *nextTidyNode( TidyNodeIter *pThis )
{
    if (NULL == pThis->pCurrent)
    {
        /* just starting out, initialize */
        pThis->pCurrent = pThis->pTop->content;
    }
    else if (NULL != pThis->pCurrent->content)
    {
        /* the next element, if any, is my first-born child */
        pThis->pCurrent = pThis->pCurrent->content;
    }
    else 
    {
        /* no children, I guess my next younger brother inherits the throne. */
        while (   NULL == pThis->pCurrent->next
               && pThis->pTop != pThis->pCurrent->parent )
        {
            /* no siblings, do any of my ancestors have younger sibs? */
            pThis->pCurrent = pThis->pCurrent->parent;
        }
        pThis->pCurrent = pThis->pCurrent->next;
    }
    return pThis->pCurrent;
}

void setCurrentNode( TidyNodeIter *pThis, Node *newCurr )
{
    if (NULL != newCurr)
        pThis->pCurrent = newCurr;
}