Example #1
0
HRESULT CKhParser::fillHomonyms(BSTR response)
{
    wchar_t* str(response);
    int i = 0;
    const wchar_t* foundStem = L"FOUND STEM:";
    homonyms.clear();
    hom homonym;
    wchar_t* tmp = wcsstr(str, foundStem);
    while (tmp != 0) {
        tmp = tmp + 12;
        // grammatics
        wchar_t* form = getDetails(tmp, L' ');
        // affixes
        wchar_t* affixes = getDetails(wcschr(tmp, L' '), 0xA);

        tmp = wcschr(tmp, 0xA);
        if (tmp == 0)
            continue;
        tmp = wcschr(tmp, L' ');
        if (tmp == 0)
            continue;
        // headword
        wchar_t* headword = getSubstr(tmp, L' ');
        tmp = wcschr(tmp, 0x201B);
        if (tmp == 0)
            continue;
        tmp = tmp + 1;
        // meaning
        wchar_t* meaning = getSubstr(tmp, 0x2019);
        tmp = wcschr(tmp, 0x2019) + 1;
        wchar_t* stem = getSubstr(tmp, 0xA);
        if (stem[0] != 0x0) {
            for (i = (int)wcslen(stem) - 1; i >= 0; i--)
                if (stem[i] == L' ')
                    stem[i] = 0x0;
        }
        if (stem[0] != 0x0)
            homonym.khak = std::wstring(stem);
        else
            homonym.khak = std::wstring(headword);
        homonym.khak.append(affixes);
        homonym.rus = std::wstring(meaning).append(form);

        homonyms.push_back(homonym);
        tmp = tmp = wcsstr(tmp, foundStem);
     }
    return S_OK;
}
void Message::toMessage(string msg) {
	/* local variables */
	int i, len, x;
	string temp = "";
	time_t t_temp;
	
	/* algorithm */
	if (msg[0]=='4') {
		i = 2;
		len = msg.length();
		//sender
		temp = getSubstr(msg, i, ';');
		setSender(temp);
		temp = "";
		//receiver
		i++;
		temp = getSubstr(msg, i, ';');
		setReceiver(temp);
		temp = "";
		//timestamp
		i++;
		temp = getSubstr(msg, i, ';');
		istringstream buffer(temp);
		int x;
		buffer >> x;
		t_temp = x;
		setTimestamp(t_temp);
		temp = "";
		//message body
		i++;
		temp = getSubstr(msg, i, ';');
		text = temp;
		temp = "";
		//type
		i++;
		temp = getSubstrInt(msg, i, len);
		type = temp;
	}
Example #3
0
 bool wordPattern(string pattern, string str) {
     string map[26];
     unordered_map<string, char> rmap;
     const char* p = str.c_str();
     for (auto& c : pattern) {
         string s = getSubstr(p);
         if (s.empty()) {
             return false;
         }
         auto it = rmap.find(s);
         if (it == rmap.end()) {
             if (!map[c - 'a'].empty()) {
                 return false;
             }
             map[c - 'a'] = s;
             rmap[s] = c;
         } else {
             if (c != it->second || map[c - 'a'] != s) {
                 return false;
             }
         }
     }
     return getSubstr(p).empty();
 }
int RewriteEngine::getSubstValue( const RewriteSubstItem * pItem, HttpConnection *pConn,
                        char * &pValue, int bufLen )
{
    HttpReq * pReq = pConn->getReq();
    int type = pItem->getType();
    int i;
    if ( type < REF_STRING )
    {
        pValue = (char *)pReq->getHeader( type );
        if ( *pValue )
            return pReq->getHeaderLen( type );
        else
            return 0;
    }

/*
    if ( type >= REF_TIME )
    {
        time_t t = time(NULL);
        struct tm *tm = localtime(&t);
        switch( type )
        {
        case REF_TIME:
            i = snprintf( pValue, bufLen,
                        "%04d%02d%02d%02d%02d%02d", tm->tm_year + 1900,
                        tm->tm_mon+1, tm->tm_mday,
                        tm->tm_hour, tm->tm_min, tm->tm_sec);
            break;
        case REF_TIME_YEAR:
            i = snprintf( pValue, bufLen, "%04d", tm->tm_year + 1900);
            break;
        case REF_TIME_MON:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_mon+1 );
            break;
        case REF_TIME_DAY:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_mday);
            break;
        case REF_TIME_HOUR:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_hour);
            break;
        case REF_TIME_MIN:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_min);
            break;
        case REF_TIME_SEC:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_sec);
            break;
        case REF_TIME_WDAY:
            i = snprintf( pValue, bufLen, "%d", tm->tm_wday);
            break;
        default:
            return 0;
        }
        return i;
    }
*/
    switch( type )
    {
    case REF_STRING:
        pValue = (char *)pItem->getStr()->c_str();
        return pItem->getStr()->len();
    case REF_MAP:
        {
            MapRefItem * pRef = pItem->getMapRef();
            int len = 1024;
            char achBuf[1024];
            if ( buildString( pRef->getKeyFormat(), pConn, achBuf, len ) == NULL )
                return 0;
            if ( (len = pRef->getMap()->lookup( achBuf, len, pValue, bufLen )) == -1 )
            {
                if ( pRef->getDefaultFormat() )
                {
                    if ( buildString( pRef->getDefaultFormat(), pConn,
                                    pValue, bufLen ) == NULL )
                        return 0;
                    len = bufLen;
                }        
                else
                    len = 0;
            }
            return len;
        }
        break;             
    case REF_RULE_SUBSTR:
        return getSubstr( m_pSourceURL, m_ruleVec, m_ruleMatches, pItem->getIndex(),
                    pValue, m_flag & RULE_FLAG_BR_ESCAPE );
    case REF_COND_SUBSTR:
        return getSubstr( m_pCondBuf, m_condVec, m_condMatches, pItem->getIndex(),
                    pValue, m_flag & RULE_FLAG_BR_ESCAPE );
    case REF_ENV:
        pValue = (char *)RequestVars::getEnv( pConn, pItem->getStr()->c_str(), 
                    pItem->getStr()->len(), i );
        if ( !pValue )
        {
            i = 0;
        }
        return i;
    case REF_HTTP_HEADER:
        pValue = (char *)pReq->getHeader( pItem->getStr()->c_str(),
                        pItem->getStr()->len(), i );
        if ( !pValue )
            i = 0;
        return i;
    case REF_REQUST_FN:
    case REF_SCRIPTFILENAME:
        if ( m_iScriptLen == -1 )
        {
            pReq->checkPathInfo( m_pSourceURL, m_sourceURLLen, m_iFilePathLen,
                            m_iScriptLen, m_iPathInfoLen, m_pContext );
        }
        pValue = HttpGlobals::g_achBuf;
        //if ( m_pStrip )
        //    return m_iFilePathLen;
        //else

        //   return m_iFilePathLen + m_iPathInfoLen;
        return m_iFilePathLen;
    case REF_PATH_INFO:
        if ( m_iScriptLen == -1 )
        {
            pReq->checkPathInfo( m_pSourceURL, m_sourceURLLen, m_iFilePathLen,
                            m_iScriptLen, m_iPathInfoLen, m_pContext );
        }
        pValue = &HttpGlobals::g_achBuf[ m_iFilePathLen ];
        return m_iPathInfoLen;
    case REF_SCRIPT_NAME:
        if ( m_iScriptLen == -1 )
        {
            pReq->checkPathInfo( m_pSourceURL, m_sourceURLLen, m_iFilePathLen,
                            m_iScriptLen, m_iPathInfoLen, m_pContext );
        }
        pValue = (char *)pReq->getOrgReqURL();
        return m_iScriptLen;
    case REF_REQ_URI:   //in rewrite rule, this does not include Query String part
        if ( pReq->getRedirects() == 0 )
        {
            pValue = (char *)pReq->getOrgReqURL();
            return pReq->getOrgReqURILen();
        }
        if ( m_pStrip )
        {
            memmove( pValue, m_pStrip->c_str(), m_pStrip->len() );
            memmove( pValue + m_pStrip->len(), m_pSourceURL, m_sourceURLLen );
            return m_pStrip->len() + m_sourceURLLen;
        }
        //fall through
    case REF_CUR_URI:
        pValue = (char *)m_pSourceURL;
        return m_sourceURLLen;
    case REF_QUERY_STRING:
        pValue = (char *)m_pQS;
        return m_qsLen;
    default:
        return RequestVars::getReqVar( pConn, type, pValue, bufLen );
    }
    return 0;
}