📄 tanalyselink.cpp
字号:
// TAnalyseLink.cpp : implementation file
//
#include "stdafx.h"
#include "TAnalyseLink.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// TAnalyseLink
//-----------
TAnalyseLink::TAnalyseLink()
{
NewsDate=CTime::GetCurrentTime();
}
//----------
CString TAnalyseLink::ExtractLinkAndTitle(CString temp,bool Brief,bool Repeat)
{
CString TempString,LinkString="",filter=FUrlCharacter.TitleFilter;
CString TempBrief="简介:";
TempBrief=TempBrief+'\n';
bool Ahead=false;
int pos=1,pos1=0;
pos=FUrlCharacter.SearchKey.Find("&"); //pos=FUrlCharacter.SearchKey.AnsiPos("&");
SearchHref=FUrlCharacter.SearchKey.Mid(0,pos); // SearchHref=FUrlCharacter.SearchKey.SubString(1,pos-1);
pos1=FUrlCharacter.SearchKey.Find("@"); //pos1=FUrlCharacter.SearchKey.AnsiPos("@");
if (pos==-1||pos1==-1) return "SearchKeyError"; //if (pos==0||pos1==0) return "SearchKeyError";
SearchA=FUrlCharacter.SearchKey.Mid(pos+1,pos1-pos-1); //SearchA=FUrlCharacter.SearchKey.SubString(pos+1,pos1-pos-1);
pos=FUrlCharacter.SearchKey.Find("@@"); //pos=FUrlCharacter.SearchKey.AnsiPos("@@");
if (pos==-1) TempKey=""; //if (pos==0) TempKey="";
else {
pos1=FUrlCharacter.SearchKey.GetLength();
TempKey=FUrlCharacter.SearchKey.Mid(pos+1,pos1-pos-1);
//TempKey=FUrlCharacter.SearchKey.SubString(pos+1,pos1-pos);
}
pos=FUrlCharacter.BaseLink.Find("@@"); // pos=FUrlCharacter.BaseLink.AnsiPos("@@");
if (pos!=-1) { //if (pos!=0) {
CString link,title;
link=FUrlCharacter.BaseLink.Mid(0,pos); //link=FUrlCharacter.BaseLink.SubString(1,pos-1);
// title=FUrlCharacter.BaseLink.SubString(pos+2,
// FUrlCharacter.BaseLink.Length()-pos-1);
title=FUrlCharacter.BaseLink.Mid(pos+2,
FUrlCharacter.BaseLink.GetLength()-pos-2);
TempBaseLink=link+NewsDate.Format(title);
}
else TempBaseLink=FUrlCharacter.BaseLink;
pos=1;
if (!FUrlCharacter.VerifyDate.IsEmpty()) {
// TempString=NewsDate.FormatString(FUrlCharacter.VerifyDate.c_str());
TempString=
NewsDate.Format(FUrlCharacter.VerifyDate);
if (temp.Find(TempString)==-1) //if (temp.AnsiPos(TempString)==0)
return "";
}
if (!filter.IsEmpty()&&filter[0]=='&') {
// if (!filter.IsEmpty()&&filter[1]=='&')
// filter=filter.Delete(1,1);
filter.Delete(0,1);
filter=NewsDate.Format(filter);
}
else filter="";
if (!FUrlCharacter.StartPos.IsEmpty()) {
pos=temp.Find(FUrlCharacter.StartPos); //pos=temp.AnsiPos(FUrlCharacter.StartPos);
if (pos==-1) return "CharacterChanged"; //if (pos==0) return "CharacterChanged";
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
}
if (!FUrlCharacter.FinishPos.IsEmpty()) {
pos=temp.Find(FUrlCharacter.FinishPos); //pos=temp.AnsiPos(FUrlCharacter.FinishPos);
if (pos==-1) return "CharacterChanged"; //if (pos==0) return "CharacterChanged";
temp=temp.Mid(0,pos+1); //temp=temp.SubString(1,pos);
}
if (TempKey=="@") {
TempKey="";
if (Brief) { Ahead=true; Brief=false;}
}
else TempKey.Delete(0,1); // TempKey=TempKey.Delete(1,1);
if (TempKey.IsEmpty()) {
pos=temp.Find(SearchHref); //pos=temp.AnsiPos(SearchHref);
if (pos==-1) return "CharacterChanged"; //if (pos==0)
while (pos>-1) {
CString sstr="";
temp.Delete(0,pos); // temp=temp.Delete(1,pos-1);
pos=temp.Find(SearchA); // pos=temp.AnsiPos(SearchA);
if (pos==-1) break; //if (pos==0)
// TempString=temp.SubString(1,pos+SearchA.GetLength()-1);
// temp=temp.Delete(1,pos);
TempString=temp.Mid(0,pos+SearchA.GetLength());
temp.Delete(0,pos+1);
pos=temp.Find(SearchHref); //pos=temp.AnsiPos(SearchHref);
if (Brief) {
TempBrief="";
TempBrief=temp.Mid(3,pos-6); //TempBrief=temp.SubString(4,pos-7);
TempBrief="简介:"+GetBrief(TempBrief)+'\n';
}
if (!filter.IsEmpty()) {
pos1=temp.Find(filter); //pos1=temp.AnsiPos(filter);
if (pos1==-1) break; //if (pos1==0)
if (pos1>pos) continue;
}
if (Repeat)
sstr= LinkAndTitle(TempString,"ada",true);
else sstr= LinkAndTitle(TempString,LinkString,true);
if (sstr.IsEmpty()) {
if (Ahead) {
TempBrief="";
TempBrief="<"+temp.Mid(0,pos+1); //TempBrief="<"+temp.SubString(1,pos);
TempBrief="简介:"+GetBrief(TempBrief)+'\n';
}
continue;
}
LinkString=LinkString+sstr+TempBrief;
if (Ahead) {
TempBrief="";
TempBrief="<"+temp.Mid(0,pos+1); //TempBrief="<"+temp.SubString(1,pos);
TempBrief="简介:"+GetBrief(TempBrief)+'\n';
}
}
}
else {
pos1=0;
CString TempTitle="",TempLink;
int ll=TempKey.GetLength();
pos=temp.Find(TempKey); // pos=temp.AnsiPos(TempKey);
if (pos==-1) return "CharacterChanged"; //if (pos==0)
while (pos>1) { //while (pos>0)
temp.Delete(0,pos+ll); //temp=temp.Delete(1,pos+ll-1);
pos=temp.Find(SearchA); //pos=temp.AnsiPos(SearchA);
if (pos==-1) break; //if (pos==0)
// TempString=temp.SubString(1,pos+SearchA.GetLength()-1);
TempString=temp.Mid(0,pos+SearchA.GetLength());
temp.Delete(0,pos+1); // temp=temp.Delete(1,pos);
pos=temp.Find(TempKey); //pos=temp.AnsiPos(TempKey);
if (Brief) {
TempBrief="";
TempBrief=temp.Mid(3,pos-3); //TempBrief=temp.SubString(4,pos-4);
TempBrief="简介:"+GetBrief(TempBrief)+'\n';
}
if (!filter.IsEmpty()) {
pos1=TempString.Find(filter); //pos1=TempString.AnsiPos(filter);
if ((pos1==-1)||(pos1>pos)) continue; //if ((pos1==0)||(pos1>pos))
}
pos1=TempString.Find(SearchHref); //pos1=TempString.AnsiPos(SearchHref);
TempTitle=TempString.Mid(0,pos1-7); //TempTitle=TempString.SubString(1,pos1-8);
TempTitle=ClearTitle(TempTitle,FUrlCharacter.ClearString);
TempString.Delete(0,pos1); //TempString=TempString.Delete(1,pos1-1);
TempLink=LinkAndTitle(TempString,LinkString,true);
if (TempLink.IsEmpty()) continue;
pos1=TempLink.Find('\n'); //pos1=TempLink.AnsiPos('\n');
TempLink=TempLink.Mid(0,pos1+1); //TempLink=TempLink.SubString(1,pos1);
LinkString=LinkString+TempLink+TempTitle+'\n'+TempBrief;
}
}
return LinkString;
}
//-------------------------
CString TAnalyseLink::LinkAndTitle(CString temp,CString TempLink,bool Flag)
{
int pos=0,pos1=0,length=SearchHref.GetLength();
CString link,title;
pos=temp.Find("javascript"); //pos=temp.AnsiPos("javascript");
if (pos==-1) pos=temp.Find("Javascript"); //if (pos==0)
if (pos==-1) pos=temp.Find("JavaScript");
if (pos==-1) pos=temp.Find("JAVASCRIPT");
if (pos!=-1) { // if (pos!=0)
pos=temp.Find(">") ; //pos=temp.AnsiPos(">") ;
link=temp.Find(length,pos-length); //link=temp.SubString(length+1,pos-length-1);
pos=link.Find("../") ; //pos=link.AnsiPos("../") ;
pos1=link.Find("./"); //pos1=link.AnsiPos("./");
if (pos!=-1) //if (pos!=0)
link.Insert(pos,FUrlCharacter.BaseLink); //link=link.Insert(FUrlCharacter.BaseLink,pos);
else if (pos1!=-1) //if (pos1!=0)
link.Insert(pos1,FUrlCharacter.BaseLink);// link=link.Insert(FUrlCharacter.BaseLink,pos1)
}
else {
if (temp[length]=='"') { // if (temp[length+1]=='"')
temp.Delete(0,length+1); //temp=temp.Delete(1,length+1);
pos=temp.Find('"'); //pos=temp.AnsiPos('"');
if (pos<3) { // if (pos<4)
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('"'); //pos=temp.AnsiPos('"');
}
link=temp.Mid(0,pos); //link=temp.SubString(1,pos-1);
}
// else if (temp.SubString(length+1,1)=="'") {
else if (temp.Mid(length,1)=="'") {
// temp=temp.Delete(1,length+1);
temp.Delete(0,length);
pos=temp.Find("'"); //pos=temp.AnsiPos("'");
if (pos<3) { // if (pos<4)
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find("'"); //pos=temp.AnsiPos("'");
}
link=temp.Mid(0,pos); //link=temp.SubString(1,pos-1);
}
// else if (temp.SubString(length+1,1)=="\\") {
else if (temp.Mid(length,1)=="\\") {
// temp=temp.Delete(1,length+1); //=9
temp=temp.Delete(0,length+1);
pos=temp.Find("\\"); //pos=temp.AnsiPos("\\");
if (pos<3) { // if (pos<4)
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('"'); //pos=temp.AnsiPos('"');
}
link=temp.Mid(0,pos); //link=temp.SubString(1,pos-1);
}
else {
temp.Delete(0,length); // temp=temp.Delete(1,length);
pos=temp.Find(' '); //pos=temp.AnsiPos(' ');
pos1=temp.Find('>'); //pos1=temp.AnsiPos('>');
if (pos<3||pos==-1||pos>pos1) pos=pos1; //if (pos<4||pos==0||pos>pos1)
link=temp.Mid(0,pos); //link=temp.SubString(1,pos-1);
}
}
link=ClearLink(link);
if (TempLink.Find(link)!=-1){ //if (TempLink.AnsiPos(link)!=0)
if (Flag) return "";
else return "Already Exist";
}
if (IsVidLink(link,FUrlCharacter.LinkFilter)) {
pos=temp.Find(">"); //pos=temp.AnsiPos(">");
//title=temp.Delete(1,pos);
title=temp;
title.Delete(0,pos+1);
// pos=temp.AnsiPos(SearchA);
pos=title.Find(SearchA);
title = title.Mid(0,pos); //title=temp.SubString(1,pos-1);
title=ClearTitle(title,FUrlCharacter.ClearString);
if ((link.Find("http")!=-1)||(link.Find("HTTP")!=-1)||(link.Find("Http")!=-1))
// if ((link.AnsiPos("http")!=0)||(link.AnsiPos("HTTP")!=0)||(link.AnsiPos("Http")!=0))
link=link+'\n';
else
link=TempBaseLink+link+'\n';
if (!IsVidTitle(title,FUrlCharacter.TitleFilter))
title="";
if (title.IsEmpty())
return "";
else
return link+title+'\n';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -