⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsearchserver.cpp

📁 本程序是VC为平台开发的股票资讯系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// TSearchServer.cpp : implementation file
//

#include "stdafx.h"
#include "TSearchServer.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// TSearchServer

TSearchServer::TSearchServer()
{
     FTotalRecords=0;
	 NeedAdd = false;
     FNextPageUrl=_T("");
}
//-------------------------------------
CString TSearchServer::GetSearchResult(CString ttemp,CString Key)
{
     try {
         TAnalyseLink* FALink=new TAnalyseLink;
         CopyCharacter();
         FALink->Copy(FSUrlCharacter);
         CString str="",link="",temp="";
         FUrlAddress=UrlAddress+Key;
         str=ttemp;
         str=Translate(str);
         if (TotalCharacter.IsEmpty())
             FTotalRecords=-3;
         else
             GetRecords(&ttemp);
         link=FALink->ExtractLinkAndTitle(str,true,true);

         FNextPageFlag=IsNext(&str,Key);
         delete FALink;
         if (ClearLink.Find("@")!=-1)     //if (ClearLink.AnsiPos("@")!=0)
            link=ModifyLink(link);
         if (ClearLink.Find("&")!=-1)     //if (ClearLink.AnsiPos("&")!=0)
            link=AdjustLink(link);
         if (ClearLink.Find("#")!=-1)     // if (ClearLink.AnsiPos("#")!=0)
             link=AheadBrief(link);
         if (NeedAdd)
            link=AddBaseLink(link);
         return link;
     }
     catch(...) {
          return "SearchError";
     }
}

void  TSearchServer::CopyCharacter()
{
    if (!TitleFilterAndClear.IsEmpty()){
    //int pos=TitleFilterAndClear.AnsiPos("@");
        int pos=TitleFilterAndClear.Find("@");
        if (pos==-1)  {                // if (pos==0)
            FSUrlCharacter.TitleFilter=TitleFilterAndClear;
            FSUrlCharacter.ClearString="";
        }
        else {
        //FSUrlCharacter.TitleFilter=TitleFilterAndClear.SubString(1,pos-1);
            FSUrlCharacter.TitleFilter=TitleFilterAndClear.Mid(0,pos);
        //FSUrlCharacter.ClearString=TitleFilterAndClear.Delete(1,pos);
            TitleFilterAndClear.Delete(0,pos+1);
			FSUrlCharacter.ClearString = TitleFilterAndClear;
        }
    }
    else {
         FSUrlCharacter.TitleFilter="";
         FSUrlCharacter.ClearString="";
    }
    FSUrlCharacter.InfoStyle=0;
    FSUrlCharacter.UrlName="";
    FSUrlCharacter.BaseUrl="";
    if (NextPageBaseLink.Find("@")!=-1) {     //if (NextPageBaseLink.AnsiPos("@")!=0)
        int pos=NextPageBaseLink.Find("@");     //pos=NextPageBaseLink.AnsiPos("@");
        FSUrlCharacter.BaseLink=NextPageBaseLink.Mid(0,pos);   //NextPageBaseLink.SubString(1,pos-1);
		if(FSUrlCharacter.BaseLink[0] == '&'){
			FSUrlCharacter.BaseLink.Delete(0,1);
			NeedAdd = true;
		}
		else
			NeedAdd = false;
    }
    else
        FSUrlCharacter.BaseLink="";
    if (StartPos.Find("@")!=-1) {  //if (StartPos.AnsiPos("@")!=0)
        int pos=StartPos.Find("@");   //pos=StartPos.AnsiPos("@");
        FSUrlCharacter.StartPos=StartPos.Mid(0,pos);    //StartPos.SubString(1,pos-1);
        StartPos.Delete(0,pos+1);       //StartPos=StartPos.Delete(1,pos);
    }
    else
        FSUrlCharacter.StartPos=StartPos;
    FSUrlCharacter.FinishPos=FinishPos;
    FSUrlCharacter.LinkFilter=LinkFilter;
    FSUrlCharacter.VerifyDate="";
    FSUrlCharacter.SearchKey=SearchKey;

}
//------------------------------------------
void  TSearchServer::GetRecords(CString* ttemp)
{
     CString cc1,cc2,temp;
     int pos1=-1,pos=TotalCharacter.Find("@");      
	 //pos=TotalCharacter.AnsiPos("@");
     if (!StartPos.IsEmpty())
        pos1=ttemp->Find(StartPos);       //pos1=ttemp->AnsiPos(StartPos);
     else pos1=1;
     if (pos1==-1) {
         FTotalRecords=-2;
         return;
     }
     else 
		 ttemp->Delete(0,pos1+1);     //temp=ttemp->Delete(1,pos1);
	 temp.Format("%s",*ttemp);
     if (pos==-1) { FTotalRecords=-1;  return;}  //if (pos==0)
     cc1=TotalCharacter.Mid(0,pos);    
	 //cc1=TotalCharacter.SubString(1,pos-1);
     cc2=TotalCharacter ;
//     cc2.Delete(1,pos);  //cc2=TotalCharacter.Delete(1,pos);
     cc2.Delete(0,pos+1);  //cc2=TotalCharacter.Delete(1,pos);
     pos=temp.Find(cc1);    //pos=temp.AnsiPos(cc1);
     if (pos==-1) {          // if (pos==0)
        FTotalRecords=-2;
        return;
     }
     CString ss=temp.Mid(pos-30,60);   //ss=temp.SubString(pos-30,60);
     pos=ss.Find(cc1);          //pos=ss.AnsiPos(cc1);
     if (pos==-1) {               // if (pos==0)
         FTotalRecords=-1;
         return ;
     }
     pos1=ss.Find(cc2);        // pos1=ss.AnsiPos(cc2);
     if (pos1==-1) {            // if (pos1==0)
        FTotalRecords=-2;
        return;
     }
//ss=ss.SubString(pos1+cc2.Length(),pos-pos1-cc2.Length()+1);
     ss=ss.Mid(pos1+cc2.GetLength(),pos-pos1-cc2.GetLength()+1);
     pos=ss.Find(",");   // pos=ss.AnsiPos(",");
     pos1=ss.Find(",");  // pos1=ss.AnsiPos(",");
     while(pos>-1) {         //  while(pos>0) {
        ss.Delete(pos,1);    //ss=ss.Delete(pos,1);
        pos=ss.Find(","); //pos=ss.AnsiPos(",");
     }
     while (pos1>-1) {          //while (pos1>0)
         ss.Delete(pos1,2);  
		 //ss=ss.Delete(pos1,2);
         pos1=ss.Find(",");  //pos1=ss.AnsiPos(",");
     }
     FTotalRecords=atoi(ss);     //FTotalRecords=atoi(ss.c_str());
}
//-------------------------------------------------------
bool  TSearchServer::IsNext(CString* temp,CString key)
{
    CString cc="",npbl="",ss="" ,link="",title="",linktitle,tempsearch="";
    CString pk="",tail1="",tail2="",tail3="",character=NextPageCharacter;
    int pos1=0,pos=0;
    npbl= NextPageBaseLink;
    pos=npbl.Find("@");          //pos=npbl.AnsiPos("@");
    if (pos!=-1) npbl.Delete(0,pos+1);    // if (pos!=0) npbl=npbl.Delete(1,pos);
    pos=character.Find("@");           // pos=character.AnsiPos("@");
    if (pos==-1) {                      // if (pos==0)
        FNextPageUrl="CharacterError";
        return false;
    }
    pk=character.Mid(0,pos);       //pk=character.SubString(1,pos-1);
    character.Delete(0,pos+1);     //character=character.Delete(1,pos);
    pos=character.Find("@");    //pos=character.AnsiPos("@");
    if (pos==-1) {               //if (pos==0)
        FNextPageUrl="CharacterError";
        return false;
    }
    cc=character.Mid(0,pos);  //cc=character.SubString(1,pos-1);
    character.Delete(0,pos+1);   //character=character.Delete(1,pos);
    pos=temp->Find(cc);       //pos=temp->AnsiPos(cc);
    if (pos==-1) {             //if (pos==0)
        FNextPageUrl=_T("");
        return false;
    }
    ss=*temp;
    ss.Delete(0,pos);   //ss=temp->Delete(1,pos-1);
    pos=character.Find("@");     //pos=character.AnsiPos("@");
    if (pos==-1) {                //if (pos==0)
        FNextPageUrl="CharacterError";
        return false;
    }
    tail1=character.Mid(0,pos); //tail1=character.SubString(1,pos-1);
    character.Delete(0,pos+1);  //character=character.Delete(1,pos);
    pos=character.Find("@");  //pos=character.AnsiPos("@");
    if (pos==-1) {   //if (pos==0)
        FNextPageUrl="CharacterError";
        return false;
    }
    tail2=character.Mid(0,pos);//tail2=character.SubString(1,pos-1);
    tail3=character;
    tail3.Delete(0,pos+1);  //tail3=character.Delete(1,pos);

    while (1) {
         pos=ss.Find(tail1);           //pos=ss.AnsiPos(tail1);
         linktitle=ss.Mid(0,pos+4); //linktitle=ss.SubString(1,pos+3);
         if (linktitle.Find(cc)==-1) {    // if (linktitle.AnsiPos(cc)==0)
             ss.Delete(0,pos+1);     //ss=ss.Delete(1,pos);
             pos=ss.Find(cc);  //pos=ss.AnsiPos(cc);
             if (pos==-1) {         //if (pos==0)
                FNextPageUrl=_T("");
                return false;
            }
            ss.Delete(0,pos);   //ss=ss.Delete(1,pos-1);
            continue;
         }
         link=ExtractLink(linktitle);
      //if ((linktitle.AnsiPos(tail2)!=0)&&(linktitle.AnsiPos(tail3)!=0))   break;
         if ((linktitle.Find(tail2)!=-1)&&(linktitle.Find(tail3)!=-1))   break;
         ss.Delete(0,pos+1);    // ss=ss.Delete(1,pos);
         pos=ss.Find(cc); //pos=ss.AnsiPos(cc);
         if (pos==-1) {     // if (pos==0)
             FNextPageUrl=_T("");
             return false;
         }
         ss.Delete(0,pos );       //ss=ss.Delete(1,pos-1);
    }
    if (!pk.IsEmpty()) {
        pos=link.Find(pk);    //      pos=link.AnsiPos(pk);
        ss=link.Mid(0,pos+pk.GetLength() );  
		//ss=link.SubString(1,pos+pk.Length()-1);
        link.Delete(0,pos+pk.GetLength() );  // link=link.Delete(1,pos+pk.Length()-1);
        pos=link.Find("&");      //pos=link.AnsiPos("&");
        if (pos!=-1)          // if (pos!=0)
            link.Delete(0,pos);     //link=link.Delete(1,pos-1);
        else link="";
        link=npbl+ss+key+link;
    }
    else  link=npbl+link;
    pos=ClearLink.Find("$") ;    //pos=ClearLink.AnsiPos("$") ;
    if (pos!=-1)  {                //if (pos!=0)
       cc=ClearLink.Mid(0,pos );    //cc=ClearLink.SubString(1,pos-1);
       pos=link.Find(cc);          //pos=link.AnsiPos(cc);
       while (pos>-1) {              //while (pos>0)
          link.Delete(pos,cc.GetLength());
//          link.Delete(pos-1,cc.GetLength());
		  //  link=link.Delete(pos,cc.Length());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -