Esempio n. 1
0
string BuildLog(CAvenueMsgHandler *pHandler, const map<string, vector<string> >* mapDefValue,
                const vecTriggerItem& vecItem, map<int, string>& mapKey)
{
    string value, item;
    for (vecTriggerItem::const_iterator itr = vecItem.begin(); 
        itr != vecItem.end();)
    {            
        const STriggerInfo& sInfo = *itr; 

        item = sInfo.pFunc(sInfo.strName, pHandler, SLogPara(sInfo.strDefault,sInfo.nKey), mapDefValue);

		ReplaceSpace(item);
        value.append(item);
        if (sInfo.keyType > 0 && !item.empty())
        {
            string& mapitem = mapKey[sInfo.keyType];
            if (!item.empty())
            {
                mapitem = item;
            }
        }
        if (++itr != vecItem.end())
        {
            value.append(SPLIT_STR);  
        }
    }
    return value;
}
Esempio n. 2
0
//IsTime_T:判断是否是时间戳
bool CDateTime::IsTime_T(const char *timestring,time_t &timestamp)
{
	char timestr[128];
	string timetmp(timestring);
	ReplaceSpace(timetmp,NULL,NULL);
	timestamp =(time_t)atol(timetmp.c_str());
	::sprintf(timestr,"%ld",timestamp);
	if(timetmp.length() == ::strlen(timestr))
	{	
		timestamp = ::abs(timestamp);
// 		if(timestamp >= sStamp) //大于当前时间
// 			timestamp= sStamp;
		struct tm *tmResult = localtime(&timestamp);		
		if (tmResult) {
			time_t t = mktime(tmResult);
			if(t != -1 && t == timestamp)
				return true;
			else
				return false;
		} else {
			return false;
		}
	}else{
		return false;
	}	
}
Esempio n. 3
0
//ParseStepFirst: 处理如 1天前、昨天……
bool CDateTime::ParseStepFirst(string timestr)
{
	time_t ltime = 0;
	int i = 0;
	ReplaceSpace(timestr,NULL,NULL);
	if(timestr.find("今天") != string::npos){
		this->sStamp = time(NULL);
		this->sTm = localtime_r(&sStamp,&sc);
		ClearHourMinuteSecond();
		return true;
	}else if(timestr.find("昨天") != string::npos){
		this->sStamp = time(NULL) - dayseconds;
		this->sTm = localtime_r(&sStamp,&sc);
		ClearHourMinuteSecond();
		return true;
	}else if(timestr.find("前天") != string::npos){
		this->sStamp = time(NULL) - dayseconds * 2;
		this->sTm = localtime_r(&sStamp,&sc);
		ClearHourMinuteSecond();
		return true;
	}else if(timestr.find("分钟前") != string::npos){
		return Findstr(timestr,stringminstamp);
	}else if (timestr.find("小时前") != string::npos){
		return Findstr(timestr,stringhourstamp);
	}else if(timestr.find("天前") != string::npos){
		bool ret = Findstr(timestr,stringdaystamp);
		ClearHourMinuteSecond();
		return ret;
	}else if(timestr.find("周前") != string::npos){
		bool ret = Findstr(timestr,stringweekstamp);
		ClearHourMinuteSecond();
		return ret;
	}
	return false;
}
Esempio n. 4
0
void ProxyBytes(char * buf)
{
	char * tmp1  = ReplaceSpace(buf);
	memset(buf,0,2000);
	strcpy(buf, tmp1);
	to_hex(buf,0);
	char * tmp2  = to_hex2(buf);
	memset(buf,0,2000);
	strcpy(buf, tmp2);
}
Esempio n. 5
0
int CDateTime::getHeaderDigit(string text, int p)
{
	if(p<1) return -1;  //前面至少要有一位数字
	text = text.substr(0,p);
	ReplaceSpace(text,NULL,"");
	p = text.length() - 1;
	int i=0;
	for(; p>=0; i++,p--)
	{
		if(text.at(p) < '0' || text.at(p) > '9')
		{
			if(i==0)return -1;	//前面没有数字
			 return atoi(text.substr(p+1).c_str());			 
		}
	}
	return atoi(text.substr(p+1).c_str());
}
Esempio n. 6
0
void ReplaceSpacetest(){
	char str[20]="we are  happy.";
	char* restr="%20";
	ReplaceSpace(str,restr);
	printf("%s",str);
}
Esempio n. 7
0
//得到时分秒
bool CDateTime::getHMS(string text)
{   
	int i=0;
	int atlocal;
	bool isam = false,ispm = false;
//	ReplaceSpace(text,1,NULL,"");
	ReplaceSpace(text,"时|分",":");
	ReplaceSpace(text,"秒"," ");
	size_t atcolon = text.find(":");
	
	while(atcolon != string::npos)
	{
		if(atcolon == 0 )
		{
			atcolon = text.find(":",atcolon + 1);
			continue;
		}
		if(atcolon == text.length() -1 ) return false;
		if(ISDIGIT(text.at(atcolon -1)) && ISDIGIT(text.at(atcolon +1)))
		{
			break;
		}else{
			atcolon = text.find(":",atcolon + 1);
		}
	}

	if(atcolon != string::npos)
	{	
		
		atlocal = (int)atcolon - 4;
		while(atlocal<0) atlocal++;
		string str = text.substr(atlocal,20);
		if(str.find("am")!=string::npos || str.find("AM")!=string::npos)
		{
			sTm->tm_hour = -12;
			isam =true;
		}
		if(str.find("pm")!=string::npos || str.find("PM")!=string::npos)
		{
			sTm->tm_hour = 12;	
			ispm =true;
		}
		char *finds = "a|A|p|P|m|M";
		ReplaceSpace(str,finds,"");
		char *strtmp = strdup((char *)str.c_str());
		char *savepos = NULL;
		char *strnum = mystrtok_r(strtmp,":", &savepos);
		while(strnum)
		{
			if(i==0)
			{
				atlocal = ::strlen(strnum)-2;	//去掉:两位前的字符。如去掉asd15:20中的asd
				while(atlocal<0) atlocal++;	
				strnum = strnum + atlocal;
				while(*strnum && (*strnum< '0' || *strnum>'9'))strnum++;
				//if(*strnum>= '0' && *strnum<='9')
				{
					if(isam)
					{
						sTm->tm_hour = atoi(strnum) == 12 ? 0 : atoi(strnum);
						sTm->tm_hour = ::abs(sTm->tm_hour);
					}else if(ispm){
						sTm->tm_hour = atoi(strnum) +12;				
					}else{
						sTm->tm_hour = atoi(strnum);
					}				
				}				
			}else if(i==1){
				sTm->tm_min = atoi(strnum);
			}else if(i==2){
				if (::strlen(strnum) > 2) {
					strnum[2] = 0;				//舍弃:两位后的字符。如:15:20asd中的asd
				}

				sTm->tm_sec = atoi(strnum);
			}
			strnum = mystrtok_r(NULL,":", &savepos);
			++i;
		}
		free(strtmp);
		return true;
	}
	return false;	
}
Esempio n. 8
0
bool CDateTime::ParseDateTime(const char *timeinputstr,const char *format)
{
	if(timeinputstr == NULL || ::strlen(timeinputstr) ==0) return false;
	string timeinput(timeinputstr),strtime;
	if(format != NULL)
	{
		string pattern(format);
		bool ret = parseFormatDate(timeinput,pattern);
		if(ret) return true;
	}

	strtime = timeinput;
	char *str = (char *)malloc(strtime.length()+1);
	
	if(str){
		char *strtmp = str;
		ReplaceSpace(strtime,"点","时");
		str[0] = 0;
		if(FilteTag(strtime.c_str(),str)){
			strtime = str;
			ReplaceSpace(strtime,NULL," ");
			
			if(strtime.empty())
			{
				free(strtmp);
				return false;
			}

			if(defaultparse(strtime.c_str()))
			{
				free(strtmp);
				return true;
			}else if(ParseStepFirst(strtime)){
				free(strtmp);
				return true;
			}else if(ParseStepSecond(strtime)){
				free(strtmp);
				return true;
			}else if(ParseStepThird(strtime)){
				free(strtmp);
				return true;
			}else if(ParseSteFourth(strtime.c_str())){
				free(strtmp);
				return true;
			}else if(ParseSteFifth(strtime.c_str())){
				free(strtmp);
				return true;
			}else{
				if(getHMS(strtime)){
					sTm->tm_year = sYear;
					sTm->tm_mon = sMonth;
					sTm->tm_mday = sDay;
					free(strtmp);
					return true;
				}
				
				free(strtmp);
				return false;
			}
		} else {
			free(strtmp);
			return false;
		}
	}
	return false;
}
Esempio n. 9
0
bool CDateTime::parseYMD(string text)
{
	int year =0,month = 0, day = 0;
	int date[10] = {0};
	int i = 0;
	int effectivetime = 0; 
	bool istrue = false;
	ReplaceSpace(text," |\\.|-|\\\\|-|年|月|日","/");

	char *str = strdup((char *)text.c_str());
	char *savepos = NULL;
	char *strtmp = mystrtok_r(str,"/", &savepos);
	while(strtmp)
	{
		int p = findDigit(strtmp,0);
		if(p != -1 && i<10 && strchr(strtmp,':') == NULL){
// 			int atlocal = strlen(strtmp)-4;
// 			while(atlocal<0) atlocal++;	
// 			strtmp = strtmp + atlocal;
// 			
// 			while(*strtmp< '0' || *strtmp>'9')
// 			{
// 				if(*strtmp)
// 					strtmp++;
// 				else
// 					break;
// 			}
			date[i] = atoi(strtmp + p);
			if(++effectivetime >= 2)
				istrue= true;
		}			
		strtmp = mystrtok_r(NULL,"/", &savepos);
		i++;
	}
	free(str);
	if(!istrue) return false;
	for(i=0;i<10;i++)
	{
		if(year == 0 && (date[i] > 1900 || (date[i] >0 && date[i] < 99)))	{
			year = date[i] > 1900 ? date[i] -1900 : date[i];
			continue;
		}
		if(month == 0 && date[i]<12 && day ==0){
			month = date[i];
			continue;	
		}
		if(day ==0 && date[i] <31 && (year !=0 || month !=0)){
			day = date[i];
			continue;
		}
		if(year && month && day)break;
	}
	if((year&&month)||(month&&day)){
		sTm->tm_year = year;
		sTm->tm_year = sTm->tm_year > 29? sTm->tm_year:sTm->tm_year+100;
		sTm->tm_mon = month>0?month -1:0;
		sTm->tm_mday = day == 0 ?1:day;
		return true;
	}else if(year&&day){
		sTm->tm_mon = year>0?year -1:0;
		sTm->tm_mday = day == 0 ?1:day;
		return true;
	}
	return false;
}