Exemplo n.º 1
0
Site *searchByWebSite(Site *site, Token *listTokens){
    bool match;
    Site *newSite = new Site(site->getName(), site->getAddress());
    newSite->setAddress(site->getAddress());
    int numberMatches;
    for(Token *tempToken = listTokens; tempToken != NULL; tempToken = tempToken->sig){
        //
        numberMatches = 0;
        string strToken = tempToken->getStrToken();
        string strTitle = site->getName();
        string strBody = site->getBody();
        //cout<<"TITLE"<<endl;
        for(int n = 0; n < strTitle.length(); n++){
            if(strTitle[n] == strToken[0]){
                int tempN = n; match = true;
                for(int m = 0; m < strToken.length(); m++){
                    //cout<< strTitle[tempN] << " == "<< strToken[m]<<endl;
                    if(tempN >= strTitle.length() || strTitle[tempN] != strToken[m]){
                        match = false;
                        break;
                    }
                    tempN = tempN + 1;
                }
                if(match){
                    numberMatches ++;
                }
            }
        }
        //cout<<"BODY:"<<strBody<<endl;
        for(int n = 0; n < strBody.length(); n++){
            if(strBody[n] == strToken[0]){
                int tempN = n; match = true;
                for(int m = 0; m < strToken.length(); m++){
                    //cout<< strBody[tempN] << " == "<< strToken[m]<<endl;
                    if(tempN >= strBody.length() || strBody[tempN] != strToken[m]){
                        match = false;
                        break;
                    }
                    tempN = tempN + 1;
                }
                if(match){
                    numberMatches ++;
                    //cout<<">> Match in: "<<strToken<<endl;
                }
            }
        }
        //
        if(numberMatches > 0){
            //cout<<">> Match in: "<<strToken<<endl;
            Token *newToken = new Token(tempToken->getStrToken(), numberMatches);
            newSite->addToken(newToken);
        }
    }
    return newSite;
}