Exemplo n.º 1
0
int SubstFormat::parse( const char * pCurLine, const char * pFormatStr, const char * pEnd, int isSSI, char varChar )
{
    while(( pFormatStr < pEnd )&&( isspace( *pFormatStr )))
        ++pFormatStr;
    int err = 0;
    char achVarChar[2];
    LinkedObj * pLast = head();
    SubstItem * pItem;
    achVarChar[0] = varChar;
    achVarChar[1] = 0;
    while( pFormatStr < pEnd )
    {
        pItem = new SubstItem();
        if ( !pItem )
        {
            ERR_NO_MEM( "new SubstItem()" );
            return -1;
        }
        
        if (  *pFormatStr == varChar )
        {
            if ( pFormatStr + 1 == pEnd )
            {
                HttpLog::parse_error( pCurLine ,  "Line ended with '$'" );
                err = 1;
            }
            if ( isdigit( *( pFormatStr + 1 ) ) )
            {
                pItem->setType( REF_RULE_SUBSTR );
                pItem->setIndex( *(pFormatStr + 1) - '0' );
                pFormatStr += 2;
            }
            else 
            {
                ++pFormatStr;
                if ( pItem->parseServerVar( pCurLine, pFormatStr, pEnd, isSSI ) )
                {
                    err = 1;
                }

            }
        }
        else
        {
            pItem->parseString( pFormatStr, pEnd, achVarChar );
        }
        if ( err )
        {
            delete pItem;
            return -1;
        }
        else
        {
            pLast->addNext( pItem );
            pLast = pItem;
        }
    }
    return 0;
}