Esempio n. 1
0
File: Database.cpp Progetto: wkcn/HR
bool Database::isTruth(Staff *st,Exp *filter){
	try{
		if (filter -> kind != EXP_OP)return true;
		//根据C++特性,能够自动短路的
		if (filter -> name == "and")
			return isTruth(st,filter->lv) && isTruth(st,filter->rv);
		if (filter -> name == "or")
			return isTruth(st,filter->lv) || isTruth(st,filter->rv);
		//剩下的是=,>,<,<>,!=,<=,>=
		Exp *lv = filter -> lv;
		Exp *rv = filter -> rv;	
		if (rv->kind == EXP_STR){
			//名字,字符串比较
			string name = st -> GetName();
			if (filter->name[0] == '='){
				//防止出现==输入
				return MatchStr(name,rv->name);
			}else if (filter->name == "!=" || filter -> name == "<>"){
				return !MatchStr(name,rv->name);
			}
			if (filter->name == "<")return name < rv->name;
			if (filter->name == ">")return name > rv->name;
			if (filter->name == "<=")return name <= rv->name;
			if (filter->name == ">=")return name >= rv->name;
		}else{
			int num = GetStaffValue(st,lv->name);
			int vn = STOI(rv->name);
			if (filter -> name[0] == '=')return num == vn;
			if (filter -> name == "!=" || filter -> name == "<>")return num != vn;
			if (filter -> name == "<")return num < vn;
			if (filter -> name == ">")return num > vn;
			if (filter -> name == "<=")return num <= vn;
			if (filter -> name == ">=")return num >= vn;
		}
	}catch(...){
		return false;
	}
	return true;//出现异常,暂时不处理
}
Esempio n. 2
0
char* CRegex::ReplaceString(const char* subject, int32 len, const char* repl)
{
	if (!subject || fInitCheck != B_OK || fMatchInfos.empty())
		return NULL;
	
	BString replStr;

	char c;
	int rl = strlen(repl);
	for(int i=0; i<rl; ++i)
	{
		c = repl[i];
		if (c == '\\' || c == '$')
		{
			c = repl[++i];
			if (c >= '1' && c <= '9')
				replStr << MatchStr(subject, c-'0');
			else if (c == '\\') 
			{	// de-escape newline, carriage-return, tab and backslash:
				if (c == 'n')
					replStr << '\n';
				else if (c == 'r')
					replStr << '\r';
				else if (c == 't')
					replStr << '\t';
				else if (c == '\\')
					replStr << '\\';
			}
		}
		else
			replStr << c;
	}
	char* resBuf = (char*)malloc(replStr.Length()+1);
	if (resBuf)
	{
		replStr.CopyInto(resBuf, 0, replStr.Length());
		resBuf[replStr.Length()] = '\0';
	}
	return resBuf;
}