char * RewriteEngine::buildString( const RewriteSubstFormat * pFormat, HttpConnection * pConn,
                          char * pBuf, int &len, int esc_uri, int noDupSlash )
{
    char * pBegin = pBuf;
    char * pBufEnd = pBuf + len - 1;
    const RewriteSubstItem * pItem = pFormat->begin();
    
//    if ( !pItem->next() )
//    {
//        int valLen = getSubstValue( pItem, pConn, pBegin, pBufEnd );
//        return valLen;
//        //only one variable, no need to copy to buffer
//    }

    while( pItem )
    {
        if ( appendSubst( pItem, pConn, pBegin, pBufEnd, esc_uri,
                        (pBegin>pBuf)?noDupSlash:0 ) == -1 )
            return NULL;
        pItem = (const RewriteSubstItem *)pItem->next();
    }
    *pBegin = 0;
    len = pBegin - pBuf;
    return pBuf;
}
char * RequestVars::buildString( const SubstFormat * pFormat, HttpSession *pSession,
                            char * pBuf, int &len, int noDupSlash, 
                            const RegexResult * pRegRes, const char * pTmFmt )
{
    char * pBegin = pBuf;
    char * pBufEnd = pBuf + len - 1;
    const SubstItem * pItem = pFormat->begin();
    
//    if ( !pItem->next() )
//    {
//        int valLen = getSubstValue( pItem, pSession, pBegin, pBufEnd );
//        return valLen;
//        //only one variable, no need to copy to buffer
//    }

    while( pItem )
    {
        if ( appendSubst( pItem, pSession, pBegin, pBufEnd - pBegin,
                        (pBegin>pBuf)?noDupSlash:0, pRegRes, pTmFmt ) == -1 )
            return NULL;
        pItem = (const SubstItem *)pItem->next();
    }
    *pBegin = 0;
    len = pBegin - pBuf;
    return pBuf;
}