/**  Turn user input keyword to regular expression.
 *   For instance, if user input is "green|yellow|blue", regular expression input should be "(green)|(yellow)|(blue)". The parentheses are used for backtrace when the matched part should be replaced with color escape code.
 *  @param [in] update_rgEprStr. user input regular expression to search (e.g. green|yellow|blue)
 *  @param [out] rgEprStr regular expression
 */
void log_analysis_tool::set_rgEprStr(const char* update_rgEprStr)
{
    numOfKeyword = 1;
    for(int i=0; update_rgEprStr[i]!='\0'; i++){
      if(update_rgEprStr[i]=='|')numOfKeyword++;
    }

    string formatter_tmp("($1)");
    string partial_fmt;
    string backReference_tmp("(.+)");
    string another_backReference_tmp("\\|(.+)");
    string brph;
    for (int i = 1 ; i< numOfKeyword; i++)
    {
        backReference_tmp = backReference_tmp + another_backReference_tmp;
        partial_fmt = '1' + i;
        partial_fmt = "|($" + partial_fmt + ')';
        formatter_tmp     = formatter_tmp + partial_fmt;
    }

    boost::regex expression_tmp(backReference_tmp);
    string       line_tmp(update_rgEprStr);
    rgEprStr = boost::regex_replace(line_tmp, expression_tmp, formatter_tmp.data());

}
Exemple #2
0
	const std::string CDataParser::ParseContent(const std::string &line)
	{
		if (line.size() <= 1)
		{
			return std::string("");
		}
		std::string line_tmp(line);
		std::vector<std::string> data_vec;
		int sep, tmp;
		// separate the data by the SEPARATORs
		while (line_tmp.size())
		{
			sep = line_tmp.size();
			for (size_t i = 0; i < SEPARATOR.size(); ++ i)
			{
				tmp = line_tmp.find(SEPARATOR.at(i));
				if (tmp >= 0 && sep > tmp)
				{
					sep = tmp;
				}
			}
			data_vec.push_back(line_tmp.substr(0, sep));
			line_tmp.erase(0, sep + 1);
		}
		std::stringstream ss;
		double data[TITLE_SIZE];
		// read data
		for (size_t i = 0; i < TITLE_SIZE; ++ i)
		{
			if (m_title_pos[i] > 0 && data_vec.size() > m_title_pos[i])
			{
				ss.clear();
				ss << data_vec.at(m_title_pos[i] - 1);
				ss >> data[i];
			}
			else
			{