📄 functions.cpp
字号:
#include "Functions.h"
Functions::Functions()
{
}
Functions::~Functions()
{
}
string Functions::getString(string content, int pos)
{
int i=0;
size_t endPos = content.find(" ");
while(++i<pos)
{
content = content.substr(content.find(" ")+1);
endPos = content.find(" ");
}
return content.substr(0, endPos);
}
/*
string Functions::GetUrlDomain(string url)
{
string url_regex = "^http:\\/\\/((\\w+\\.)+\\w+)\\/[\\/\\w\\d?%\\-&~@=.]+$";
match_results<std::string::const_iterator> what;
regex r(url_regex.c_str());
FileOperator fo;
if(regex_match(url, what, r, boost::match_default | boost::match_partial))
{
return what[1].str();
}
return "";
}*/
unsigned int Functions::PowUInt(unsigned int bottom, unsigned int power)
{
if(power==0)
return 1;
unsigned int result=1;
while(power-->0)
{
result = bottom * result;
}
return result;
}
int Functions::Hex2Decimal(string hex)
{
if(hex.empty())
{
return 0;
}
int number = 0;
int step=1;
int total=0;
char ch=0;
string sch="";
for(int hex_i = hex.size()-1; hex_i >= 0; hex_i--)
{
ch = hex[hex_i];
sch = hex[hex_i];
switch(ch)
{
case 'a':
case 'A':number = 10; break;
case 'b':
case 'B':number = 11; break;
case 'c':
case 'C':number = 12; break;
case 'd':
case 'D':number = 13; break;
case 'e':
case 'E':number = 14; break;
case 'f':
case 'F':number = 15; break;
default:number = atoi(sch.c_str());
}
total = total + number * step;
step = step * 16;
}
return total;
}
int Functions::pcre_match(string pattern, string &subject, int *poffset, map<int, string> &match_result, int *pos)
{
const char *pError=NULL;
int nError=0, offset=*poffset;
int nSubLen = 0;
int nRc=0;
int anOvector[100]={-1};
pcre *pRe=NULL; unsigned long int flags = PCRE_MULTILINE | PCRE_NEWLINE_CRLF | PCRE_DOTALL;
pRe=pcre_compile(pattern.c_str(), 0, &pError, &nError, NULL);
if (pRe == NULL)
{
return 1;
}
nSubLen = subject.size(); flags = PCRE_NEWLINE_CRLF;
nRc = pcre_exec(pRe, NULL, subject.c_str(), nSubLen, offset, 0, anOvector, 100);
if(nRc==PCRE_ERROR_NOMATCH)
{ pcre_free(pRe); return 2;
}
match_result.clear();
for(int i=0; i<nRc; i++)
{ string tmp = ""; if((size_t)anOvector[2*i]<subject.size() && anOvector[2*i+1]-anOvector[2*i] > 0 ) { tmp = subject.substr(anOvector[2*i], anOvector[2*i+1]-anOvector[2*i]); }
if(pos!=NULL) { *(pos++) = anOvector[2*i]; *(pos++) = anOvector[2*i+1]; }
cout << i << ":" << tmp << endl;
match_result.insert(make_pair(i, tmp));
}
*poffset = anOvector[1]; pcre_free(pRe); return 0;
};int Functions::get_time(string &s){ time_t rawtime; struct tm * timeinfo; char buffer [80]; time ( &rawtime ); timeinfo = localtime ( &rawtime ); strftime (buffer,80,"%Y-%m-%d %H:%m:%S",timeinfo); s = buffer; return 0;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -