SquirrelObject RegularExpression::findAll(const std::string& str)
{
	try {
		size_t pos = 0;
		SquirrelObject res = SquirrelVM::CreateArray(0);
		while (pos <= str.length()) 
		{
			if ( pcre_->search(str, pos)) 
			{ 
				pos = pcre_->get_match_end()+1;
				int count = matchesCount();
				SquirrelObject mat = SquirrelVM::CreateArray(count);
				for ( int i = 0; i < count; i++ ) {
					mat.SetValue(i, pcre_->get_match(i).c_str());
				}
				res.ArrayAppend(mat);
			}
			else {
				break;
			}
		}
		return res;
	} catch( Pcre::exception ex ) {
		LOG(ERROR) << ex.what();
		return SquirrelObject();
	}
}
Пример #2
0
SquirrelObject GetAppVersion() {
	SquirrelObject res = SquirrelVM::CreateTable();
	std::string ver = _APP_VER;
	std::vector<std::string> tokens;
	IuStringUtils::Split(ver,".", tokens, 3);
	if ( tokens.size() >=3 ) {
		res.SetValue("Major", (SQInteger)IuCoreUtils::stringToint64_t(tokens[0]));
		res.SetValue("Minor", (SQInteger)IuCoreUtils::stringToint64_t(tokens[1]));
		res.SetValue("Release", (SQInteger)IuCoreUtils::stringToint64_t(tokens[2]));
		res.SetValue("Build", (SQInteger)IuCoreUtils::stringToint64_t(BUILD));
		bool isGui = 
#ifndef IU_CLI
			true;
#else 
			false;
#endif
		res.SetValue("Gui",isGui);
	}
	return res;
}
/*
RegularExpression::RegularExpression(const RegularExpression& r)
{
	
}
*/
SquirrelObject RegularExpression::split(const std::string& piece)
{
	try {
		std::vector<std::string> res = pcre_->split(piece);
		SquirrelObject obj = SquirrelVM::CreateArray(res.size());
		for( int i = 0; i  < res.size(); i++ ) {
			obj.SetValue(i, res[i].c_str());
		}
		return obj;
	} catch( Pcre::exception ex ) {
		LOG(ERROR) << ex.what();
		return SquirrelObject();
	}
}
SquirrelObject RegularExpression::getSubStrings()
{
	try {
		std::vector<std::string>* substrings =  pcre_->get_sub_strings();
		if ( !substrings ) {
			return SquirrelObject();
		}
		SquirrelObject res = SquirrelVM::CreateArray(substrings->size());
		for ( int i = 0; i < substrings->size(); i++ ) {
			res.SetValue(i, (*substrings)[i].c_str());
		}
		return res;
	} catch( Pcre::exception ex ) {
		LOG(ERROR) << ex.what();
		return SquirrelObject();
	}
}