Пример #1
0
int resolveExplicit(int level, int dir, int *pcls, int *plevel, int cch, int nNest) {
    // always called with a valid nesting level
    // nesting levels are != embedding levels
    int nLastValid;
    int ich;
    
    nLastValid = nNest;

    // process the text
    for (ich = 0; ich < cch; ich++) {
        int cls = pcls[ich];
        switch (cls) {
            case LRO:
            case LRE:
                nNest++;
                
                if (GreaterEven(level) <= MAX_LEVEL) {
                    plevel[ich] = GreaterEven(level);
                    pcls[ich] = BN;
                    ich += resolveExplicit(plevel[ich], (cls == LRE ? N : L),
                                           &pcls[ich+1], &plevel[ich+1],
                                           cch - (ich+1), nNest);
                    nNest--;
                    continue;
                }
                
                cls = pcls[ich] = BN;
                break;
                
            case RLO:
            case RLE:
                nNest++;
                
                if (GreaterOdd(level) <= MAX_LEVEL) {
                    plevel[ich] = GreaterOdd(level);
                    pcls[ich] = BN;
                    ich += resolveExplicit(plevel[ich], (cls == RLE ? N : R),
                                           &pcls[ich+1], &plevel[ich+1],
                                           cch - (ich+1), nNest);
                    nNest--;
                    continue;
                }
                
                cls = pcls[ich] = BN;
                break;
                
            case PDF:
                cls = pcls[ich] = BN;
                
                if (nNest) {
                    if (nLastValid < nNest) {
                        nNest--;
                    } else {
                        cch = ich; // break the loop, but complete body
                    }
                }
                break;
        }
        
        // Apply the override
        if (dir != N) {
            cls = dir;
        }
        
        plevel[ich] = level;
        
        if (pcls[ich] != BN) {
            pcls[ich] = cls;
        }
    }
    
    return ich;
}
Пример #2
0
static int resolveExplicit(int level, int dir, WORD *pcls, WORD *plevel, int cch, int nNest)
{
    /* always called with a valid nesting level
       nesting levels are != embedding levels */
    int nLastValid = nNest;
    int ich = 0;

    /* check input values */
    ASSERT(nNest >= 0 && level >= 0 && level <= MAX_LEVEL);

    /* process the text */
    for (; ich < cch; ich++)
    {
        WORD cls = pcls[ich];
        switch (cls)
        {
        case LRO:
        case LRE:
            nNest++;
            if (GreaterEven(level) <= MAX_LEVEL - (cls == LRO ? 2 : 0))
            {
                plevel[ich] = GreaterEven(level);
                pcls[ich] = BN;
                ich += resolveExplicit(plevel[ich], (cls == LRE ? N : L),
                            &pcls[ich+1], &plevel[ich+1],
                             cch - (ich+1), nNest);
                nNest--;
                continue;
            }
            cls = pcls[ich] = BN;
            break;

        case RLO:
        case RLE:
            nNest++;
            if (GreaterOdd(level) <= MAX_LEVEL - (cls == RLO ? 2 : 0))
            {
                plevel[ich] = GreaterOdd(level);
                pcls[ich] = BN;
                ich += resolveExplicit(plevel[ich], (cls == RLE ? N : R),
                                &pcls[ich+1], &plevel[ich+1],
                                 cch - (ich+1), nNest);
                nNest--;
                continue;
            }
            cls = pcls[ich] = BN;
            break;

        case PDF:
            cls = pcls[ich] = BN;
            if (nNest)
            {
                if (nLastValid < nNest)
                {
                    nNest--;
                }
                else
                {
                    cch = ich; /* break the loop, but complete body */
                }
            }
        }

        /* Apply the override */
        if (dir != N)
        {
            cls = dir;
        }
        plevel[ich] = level;
        if (pcls[ich] != BN)
            pcls[ich] = cls;
    }

    return ich;
}