Esempio n. 1
0
uint32_t JumpTargetExtractor::getBBAddrFromLineWithOffset(string line)
{
	smatch what;
	string function_name;
	uint32_t src_offset;

	if(regex_search(line, what, re_func_name, match_default))
	{
		string str = what[0];
		function_name = regex_replace(str, regex("\""), "", match_default | format_all);
//		LOG_DEBUG(logger, "found Function: " << function_name);
	}
	else
		assert(false);

	src_offset = getSourceOffsetFromLine(line);

	for(uint32_t i = 0; i < function_table.size(); i++)
	{
		if(function_name.compare(function_table[i].label) == 0)
		{
			return (function_table[i].address + src_offset);
		}
	}
			
	// error
	return 0x0;
}
inline std::basic_string<charT> regex_merge(const std::basic_string<charT>& s,
                         const basic_regex<charT, traits>& e, 
                         const std::basic_string<charT>& fmt,
                         match_flag_type flags = match_default)
{
   return regex_replace(s, e, fmt, flags);
}
Esempio n. 3
0
    string normalizeStd ( string str )
    {
        string str_mod = str;
        sregex rex = sregex::compile ( "(<skipped>)" );
        string replace ( "" );
        str_mod = regex_replace ( str_mod, rex, replace );

        rex = sregex::compile ( "-\n" );
        replace = ( "" );
        str_mod = regex_replace ( str_mod, rex, replace );

        rex = sregex::compile ( "\n" );
        replace = ( " " );
        str_mod = regex_replace ( str_mod, rex, replace );

        rex = sregex::compile ( "&quot;" );
        replace = ( "\"" );
        str_mod = regex_replace ( str_mod, rex, replace );

        rex = sregex::compile ( "&amp;" );
        replace = ( "& " );
        str_mod = regex_replace ( str_mod, rex, replace );

        rex = sregex::compile ( "&lt;" );
        replace = ( "<" );
        str_mod = regex_replace ( str_mod, rex, replace );

        rex = sregex::compile ( "&gt;" );
        replace = ( ">" );
        str_mod = regex_replace ( str_mod, rex, replace );

        return str_mod;
    }
Esempio n. 4
0
inline OutputIterator regex_merge(OutputIterator out,
                         Iterator first,
                         Iterator last,
                         const basic_regex<charT, traits>& e, 
                         const charT* fmt, 
                         match_flag_type flags = match_default)
{
   return regex_replace(out, first, last, e, fmt, flags);
}
Esempio n. 5
0
void Regex::replace_all(String* input, const String& format) {
	std::wstring wsFormat = format.ToStdWstring();
	std::wstring wsInput = input->ToStdWstring();

	std::wstring output;
	regex_replace(insert_iterator<std::wstring>(output, output.end()),
	              wsInput.begin(), wsInput.end(), regex, wsFormat, boost::format_sed);
	*input = wxString(output);
}
Esempio n. 6
0
inline OutputIterator regex_replace(OutputIterator out,
                         Iterator first,
                         Iterator last,
                         const basic_regex<charT, traits>& e, 
                         const std::basic_string<charT>& fmt,
                         match_flag_type flags = match_default)
{
   return regex_replace(out, first, last, e, fmt.c_str(), flags);
}
Esempio n. 7
0
/* Given an sql_options string returns a copy of the string adjusted as
 * necessary.  In particular if string the contains SQL_OPTION_TO_REMOVE it is
 * removed along with comma separator.
 */
std::string
adjust_sql_options_string(const std::string& str)
{
/* Regex that finds the SQL_OPTION_TO_REMOVE as the first, last, or middle of a
 * comma-delimited list.
 */
    boost::regex reg{"(?:," SQL_OPTION_TO_REMOVE "$|\\b"
            SQL_OPTION_TO_REMOVE "\\b,?)"};
    return regex_replace(str, reg, std::string{""});
}
Esempio n. 8
0
std::basic_string<charT> regex_replace(const std::basic_string<charT>& s,
                         const basic_regex<charT, traits>& e, 
                         Formatter fmt,
                         match_flag_type flags = match_default)
{
   std::basic_string<charT> result;
   re_detail::string_out_iterator<std::basic_string<charT> > i(result);
   regex_replace(i, s.begin(), s.end(), e, fmt, flags);
   return result;
}
Esempio n. 9
0
/**
 * A debug method. Takes as input a vector and reconstructs it according to a given vocabulary.
 * The reconstructed vector is printed to the output.
 * */
void Classifier::reconstruct_vector(string input_vector, string output_texts, string vocabulary_file) {
	// Initialization
	FreqVocabulary* voc = new FreqVocabulary(vocabulary_file.c_str());
	FILE* f = fopen(output_texts.c_str(), "w");
	if (!f){
		printf("Can not open file %s\n", output_texts.c_str());
		return;
	}
	regex remove_parse_pattern(":\\d+\\.\\d+", regex_constants::icase|regex_constants::perl);
	regex remove_parse_pattern2("-1\\s+", regex_constants::icase|regex_constants::perl);
	regex remove_parse_pattern3("\\+1\\s+", regex_constants::icase|regex_constants::perl);
	regex whitespace_pattern("\\s+");
	ifstream vectors_file;
	vectors_file.open(input_vector.c_str());
	string line;

	// Read vector lines
	getline(vectors_file,line);
	while (vectors_file) {
		//Tokenize the vector line
		string filename;
		filename = regex_replace(line, remove_parse_pattern, "");
		filename = regex_replace(filename, remove_parse_pattern2, "");
		filename = regex_replace(filename, remove_parse_pattern3, "");

		sregex_token_iterator token_it(filename.begin(), filename.end(), whitespace_pattern, -1);
		sregex_token_iterator end_it;

		// Write tokens of the line
		while(token_it != end_it) {
			string token = *token_it;
			long id = strtol(token.c_str(),NULL,10);
			fprintf(f, "%s:%ld ", voc->get_word_by_id_debug(id).c_str(), id);
			token_it++;
		}

		fprintf(f, "\n");
		getline(vectors_file,line);
	}

	fclose(f);
	delete voc;
}
Esempio n. 10
0
wstring fix_note(wstring oldstr) //修正句子中注释结构
{
	//regex是在运行时“编译”的,因此构造效率较低,使用static避免重复构造
	static wstring partten = L"//;(.+?);(.+?):";
	static wregex reg(partten);
	static wstring fmt = L"$1";

	wstring newstr;
	newstr = regex_replace(oldstr, reg, fmt);
	return newstr;
}
std::string GLDProcessFunc::createCommandLine(const string & program, const list<string> & arguments)
{
    string args;
    if ("" != program)
    {
        string semicolon = "\"";
        string space = " ";
        string programName = program;

        if (!startsWith(programName, semicolon) && !endsWith(programName, semicolon) && programName.find(' ') != string::npos)
        {
            programName = semicolon + programName + semicolon;
        }

        std::replace(programName.begin(), programName.end(), '/', '\\');

        // add the prgram as the first arg ... it works better
        args = programName + space;
    }

    for (size_t i = 0; i < arguments.size(); ++i)
    {
        std::list<string>::const_iterator it = arguments.begin();
        std::advance(it, i);
        string tmp = *it;

        // Quotes are escaped and their preceding backslashes are doubled.
        regex reg("(\\\\*)\"");
        string after = "\\1\\1\\\"";
        regex_replace(tmp, reg, after);

        if ("" == tmp || tmp.find(' ') != string::npos || tmp.find('\t') != string::npos)
        {
            // The argument must not end with a \ since this would be interpreted
            // as escaping the quote -- rather put the \ behind the quote: e.g.
            // rather use "foo"\ than "foo\"
            int i = tmp.length();

            while (i > 0 && tmp.at(i - 1) == '\\')
            {
                --i;
            }

            tmp.insert(i, 1, '"');
            tmp.insert(0, 1, '"');
        }

        args += ' ' + tmp;
    }

    return args;
}
Esempio n. 12
0
string split_word(string mid)
{
    regex pattern("(\\*|\\^|\\(|\\)|,)");
    string replace=" $& ";
    string str=regex_replace(mid,pattern,replace);
    string::iterator it;
    it=str.begin();
    if(*it==' ') str.erase(it);
    it=str.end();
    it--;
    if(*it==' ') str.erase(it);
    return str;
}
Esempio n. 13
0
void CHtmlInputLogic::MsgFormatInput(CString& strText)
{
	strText.Replace(L" tag=\"c_i\"", L"");
	strText.Replace(L" tag=\"j_i\"", L"");


	static std::wstring format1( L"[I:0:$2]" );
	static std::wstring format2( L"[I:1:$2.$3]");
	static std::wstring format3( L"[I:2:$2.$3]");
	static std::wstring format4( L"$2" );
	static std::wstring format5( L"[A:0:$1]" );

	wstring strMsg = strText.GetBuffer();

	strMsg = regex_replace(strMsg, m_regex[0], format1);
	strMsg = regex_replace(strMsg, m_regex[1], format2);
	strMsg = regex_replace(strMsg, m_regex[2], format3);
	strMsg = regex_replace(strMsg, m_regex[3], format4);
	strMsg = regex_replace(strMsg, m_regex[4], format5);

	strText = strMsg.c_str();
}
Esempio n. 14
0
//remove leading and trailing white space and doble white spaces inbetween text
string Utility::removeWhiteSpace(string sentence)
{
  boost::regex spaces("[ ]{2,}");
  return regex_replace(sentence, spaces, " ");
  
/*  
    //trim leading and trailing white spaces
	boost::algorithm::trim(sentence);
	sentence = boost::regex_replace(sentence,boost:: regex("\\s+"), " ");
//	sentence = regex_replace(sentence,regex("\\s+"), " ");
	return sentence;
  */      
}
Esempio n. 15
0
File: SAM.cpp Progetto: vezzi/ERNE
/*static*/ void SAM::regex_header(bam_header_t * header, const char * pattern, const char * replace) {
	string old_s(header->text, header->l_text);

	regex re(pattern);
	if (regex_search(old_s, re)) {
		string rep(replace);
		string new_s = regex_replace (old_s, re, rep);

		free(header->text);
		header->l_text = new_s.size();
		header->text = (char *)malloc(header->l_text);
		memcpy(header->text,new_s.c_str(),header->l_text);
	}
}
Esempio n. 16
0
//-----------------------------------------------------------------------------
string EQCmdMacro::ResolveCommandText (string rawTxt, vector<string> * args) {
    char   buffer[SMALL_BUFFER];
    int    cursor  = 0;
    string cmdText = string(rawTxt);
    
    vector<string>::iterator it;
    for (it = args->begin(); it != args->end(); ++it) {
        snprintf(buffer, SMALL_BUFFER, "<arg%d>", cursor);
        cmdText = regex_replace(cmdText, regex(buffer), *it);
        ++cursor;
    }
    
    return cmdText;
}
Esempio n. 17
0
string GLFuncs::getVersionFromStr(char* str) {
	string result;
	if (str == NULL) {
		result = "";
	}
	else {
		string string_str(str);
		regex re("^(\\d+)\\.(\\d+).*$");

		// This will return a string with an integer with the Major and minor part of the version.
		result = regex_replace(string_str, re, "$1$2");
	}
	return result;
}
Esempio n. 18
0
	map<string, int> words(string const &text) {
	  map<string, int> words;

	  /* This feels hacky, but short of writing a custom tokenizer,
	     it also feels like the simplest solution to these tests. */
	  regex re("^[']|[[:space:]]+[']|[']+[[:space:]]|[']$");
	  string result = regex_replace(text,re," ");

	  char_separator<char> sep(",.:!&@$%^&\n ");
	  tokenizer<char_separator<char>> tokens(result, sep);

	  for (auto &&word: tokens) words[to_lower_copy(word)] += 1;

	  return words;
	}
Esempio n. 19
0
    bool string_formatter::replace_params(const string& source, const map<string, string>& exp_replace_map, string* dest) const
    {
        string source_temp(source);

        for (auto exp_replace_it = exp_replace_map.begin(); exp_replace_it != exp_replace_map.end(); exp_replace_it++)
        {
            string destTemp;
            regex e(exp_replace_it->first);
            regex_replace(back_inserter(destTemp), source_temp.begin(), source_temp.end(), e, exp_replace_it->second);
            source_temp = destTemp;

        }
        *dest = source_temp;
        return true;
    }
Esempio n. 20
0
    Route::Route( Http::HttpMethod method, string path, ControllerAction action ) {
        method_ = method;
        action_ = action;

        string path_;

        regex param_regex("\\{([A-Za-z]+)\\}");
        regex_iterator<string::iterator> end;
        regex_iterator<string::iterator> match( path.begin(), path.end(), param_regex );
        while( match != end ) {
            path_params_.push_back( (*match)[1] );
            match++;
        }
        path_ = regex_replace ( path, param_regex, "(.+)" );
        path_regex_ = regex( path_ );
    }
Esempio n. 21
0
string detectOCR::detectOCRusingTesseract(Mat &image) 
{
    Mat mserMask = createMSERMask(image); 
   // imshow("mser", mserMask); 
   // waitKey(30); 
    //set tesseract
    tesseractApi.SetImage((uchar*) mserMask.data, mserMask.cols, mserMask.rows, 1, mserMask.cols);
    //get the text
    string ocrText = string(tesseractApi.GetUTF8Text());
    
    boost::regex spaces("[ ]{2,}");
    ocrText = regex_replace(ocrText, spaces, " ");
//    trim(ocrText); 
    //return detected text
    return ocrText;
}
Esempio n. 22
0
    string TH_0x1B::makeStringFromData(const data_t& data, const options_t& options)
    {
        (void)options;

        if (data.size() != dataByteCount)
        {
            throw invalid_argument("Empty data array. Needs to contain " + to_string(dataByteCount) + " bytes");
        }

        string coeffR = TH_0x00::makeStringFromData(data_t(data.begin(), data.begin() + TH_0x00::dataByteCount));
        string coeffI = TH_0x00::makeStringFromData(data_t(data.begin() + TH_0x00::dataByteCount, data.begin() + 2 * TH_0x00::dataByteCount));

        string str = dec2frac(atof(coeffR.c_str())) + "+" + dec2frac(atof(coeffI.c_str())) + "i";
        str = regex_replace(str, regex("\\+-"), "-");

        return str;
    }
Esempio n. 23
0
/*********************************************************************
*   Process all the regular expressions in a regex_list
*
*
**********************************************************************/
char *process_regex_list( char *str, regex_list *regex, int *matched )
{
    if ( DEBUG_MASK & DEBUG_REGEX && regex )
        printf("\nOriginal String: '%s'\n", str );

    while ( regex )
    {
        str = regex_replace( str, regex, 0, matched );
        regex = regex->next;

        if ( DEBUG_MASK & DEBUG_REGEX )
            printf("  Result String: '%s'\n", str );

    }

    return str;
}
Esempio n. 24
0
	void expand(std::ostream &os, const ITemplateNamespace &ns) const
	{

		auto replacer = [&](const regex::smatch &m) {

			bool needsIndent = true;
			int index = m.position() - 1;
			for(; index >= 0; --index)
			{
				if(_fmt[index] == '\n') 
				{
					break;
				}
				else if(!std::isspace(_fmt[index]))
				{
					needsIndent = false;
					break;
				}
			}

			++index;

			std::stringstream ss;

			if(needsIndent && index != m.position())
			{
				IndentingOStreambuf indenter(ss, std::string(_fmt.begin() + index, _fmt.begin() + m.position()), false);
				ns.get(m[1]).write(ss);
			}
			else
			{
				ns.get(m[1]).write(ss);
			}

			return ss.str();
		};

		auto s = regex_replace(_fmt,
		                       templateRegex,
		                       replacer);


		os << s;

	}
Esempio n. 25
0
void SHMParser::normalizeAttributes(SHMString& rawAttr, const SHMString &nodeFamily) {
	if (nodeFamily == "DeclRefExpr") {
		SHMRegex reg(" 0x[0-9a-fA-F]* '[^']+'");
		rawAttr = regex_replace(rawAttr, reg, "");
	} else if (nodeFamily == "VarDecl") {
		int i = 0;
		while (isblank(rawAttr[i])) i++;
		while (!isblank(rawAttr[i])) i++; // Delete one word and blanks
		while (isblank(rawAttr[i])) i++;
		rawAttr = rawAttr.substr(i);
	} else if (nodeFamily == "FunctionDecl") {
		int i = 0;
		while (isblank(rawAttr[i])) i++;
		while (!isblank(rawAttr[i])) i++; // Delete one word and blanks
		while (isblank(rawAttr[i])) i++;
		rawAttr = rawAttr.substr(i);
	}
}
Esempio n. 26
0
uint32_t JumpTargetExtractor::getBBAddrFromLine(string line)
{
	assert(isJindLine(line));

	smatch what;
	uint32_t bb_addr;

	if(regex_search(line, what, re_bb_addr, match_default))
	{
		string str = what[0];
		string str2 =  regex_replace(str, regex("[[:space:]]|/"), "", match_default | format_all);
		bb_addr = strtoul((str2.c_str()),NULL,16);
	}
	else
		assert(false);

	return bb_addr;
}
void ExtractClipList::AddClips(string FileName)  {
	try  { 
		if ( !SourceFile.is_open() )  {
			SourceFile.open(FileName.c_str(), ios::in);

			string file_pointer, clip_name;

			//Searching for a string "UUID:"
			while ( file_pointer != "UUID:" ) SourceFile >> file_pointer;

			//Searching for the string "####" which marsks the end of the extraction
			while ( file_pointer != "####" )  {
				if ( file_pointer == "UUID:" )  {
					clip_name.clear();

					//Advance two words to get the last strings
					SourceFile >> file_pointer >> file_pointer >> file_pointer;
					//Form the final string by extracting the remaining words from the line while looking for "UUID:"
					while ( file_pointer != "UUID:" )  {
						clip_name += file_pointer + " ";
						SourceFile >> file_pointer;
						if ( file_pointer == "####" ) break;
					 }

					AllClips.emplace_back( clip_name );
				 }
			 }


			//Shorten the names by eliminating redundant data attached to the clip's name
			for ( string& clip : AllClips )  {
				for ( pattern p : shorten_name )  {
					clip = regex_replace(clip, p.first, p.second ); 
				 }
			 }

			//Sort and store in a set
			AllClips.sort();
			CompleteList.insert<list<string>::iterator>(AllClips.begin(), AllClips.end());

			SourceFile.close();

			AllClips.clear();
		 }
Esempio n. 28
0
uint32_t JumpTargetExtractor::getTargetOffsetFromLine(string line)
{
	assert(isJindLine(line));

	smatch what;
	uint32_t tgt_offset;

	if(regex_search(line, what, re_tgt_offset, match_default))
	{
		string str = what[0];
		string str2 = regex_replace(str, regex("[[:space:]]|to"), "", match_default | format_all);
		tgt_offset = strtoul(str2.c_str(),NULL, 16);
		LOG_DEBUG(logger, "found tgt offset: " << hex << tgt_offset);
	}
	else
		assert(false);

	return tgt_offset;
}
Esempio n. 29
0
IResultPtr PerforceDepotView::createChangeList(const char* description, ChangeListId& rChangeListId)
{
	std::stringstream input;

	input << "Change:	new" << std::endl;
	input << "Client:	" << impl_->clientApi_->GetClient().Text() << std::endl;
	input << "User:	"******"Status:	new" << std::endl;
	auto formatted = regex_replace(description, std::regex("(\r\n|\r|\n)"), std::string("$1\t"));
	input << "Description:" << formatted << std::endl;
	auto result = RunCommand(std::string("change -i"), input.str());
	if (result->output() && *result->output())
	{
		// Successful output will be something like "Change 23603 created."
		std::string output(result->output());
		auto& start = *std::find(output.begin(), output.end(), ' ');
		rChangeListId = atoi(&start);
	}
	return std::move(result);
}
Esempio n. 30
0
/** Given a string such as
 *      "<glob> <glob> ... *.{abc,def} <glob>",
 *  convert the csh-style brace expresions:
 *      "<glob> <glob> ... *.abc *.def <glob>".
 *  Requires no system support, so should work equally on Unix, Mac, Win32.
 */
static string const convert_brace_glob(string const & glob)
{
	// Matches " *.{abc,def,ghi}", storing "*." as group 1 and
	// "abc,def,ghi" as group 2, while allowing spaces in group 2.
	static lyx::regex const glob_re(" *([^ {]*)\\{([^}]+)\\}");
	// Matches "abc" and "abc,", storing "abc" as group 1,
	// while ignoring surrounding spaces.
	static lyx::regex const block_re(" *([^ ,}]+) *,? *");

	string pattern;

	string::const_iterator it = glob.begin();
	string::const_iterator const end = glob.end();
	while (true) {
		match_results<string::const_iterator> what;
		if (!regex_search(it, end, what, glob_re)) {
			// Ensure that no information is lost.
			pattern += string(it, end);
			break;
		}

		// Everything from the start of the input to
		// the start of the match.
		pattern += string(what[-1].first, what[-1].second);

		// Given " *.{abc,def}", head == "*." and tail == "abc,def".
		string const head = string(what[1].first, what[1].second);
		string const tail = string(what[2].first, what[2].second);

		// Split the ','-separated chunks of tail so that
		// $head{$chunk1,$chunk2} becomes "$head$chunk1 $head$chunk2".
		string const fmt = " " + head + "$1";
		pattern += regex_replace(tail, block_re, fmt);

		// Increment the iterator to the end of the match.
		it += distance(it, what[0].second);
	}

	return pattern;
}