string ReplaceString(string source, string find, string replacement)
{
	string::size_type pos = 0;
    while((pos = source.find(find, pos)) != string::npos)
	{
        source.replace(pos, find.size(), replacement);
        pos++;
    }

	return source;
}
Example #2
0
string cppSrcGen::membaNameSet(string s)
{
    char v[2] = { 0 };

    if ((s.size() > 0) && (m_pm.setPrefix == "set"))
    {
        v[0] = s[0] - 32;
        s.replace(0, 1, v);
    }
    return m_pm.setPrefix + s;
}
Example #3
0
File: load.cpp Project: dmalmer/EMG
bool check_ID_name(string & INFO){
	bool PASSED 	= true;
	string change 	= "::";
	for (int i = 0; i < INFO.size(); i++){
		if (INFO.substr(i,1)=="|"){
			PASSED 		= false;
			INFO.replace(i, 1, change);
		}
	}
	return PASSED;
}
Example #4
0
void string_replace(string & strBig, const string & strsrc, const string &strdst)
{
	string::size_type pos=0;
	string::size_type srclen=strsrc.size();
	string::size_type dstlen=strdst.size();
	while( (pos=strBig.find(strsrc, pos)) != string::npos)
	{
		strBig.replace(pos, srclen, strdst);
		pos += dstlen;
	}
}
Example #5
0
bool cleanString(string& str, const char& quote) {

  bool begIsClean = false;
  bool endIsClean = false;
  if(!str.empty()){
    if(*(str.begin())==quote){
      str.replace(str.begin(), str.begin()+1, "");
      begIsClean = true;
    }
    if(*(str.end()-1)==quote){
      str.replace(str.end()-1, str.end(), "");
      endIsClean = true;
    }
    // erase all white space at a begining
    while(boost::algorithm::starts_with(str, " ")){
       str.erase(0,1);
    };
  }
  return (begIsClean && endIsClean);
}
//功能:用一个字符串来替换指定的源字符串中的另一个字串
//参数:
//	sSrc: string & 类型,原始的字符串
//	sOld: const string &类型,被替换的字符串
//	sNew: const string &类型,用来替换的字符串
//返回值:void
void CXxwCppPub::Replace(string & sSrc, const string & sOld, const string &sNew)
{
	string::size_type pos=0;
	string::size_type lenOld=sOld.size();
	string::size_type lenNew=sNew.size();
	while( (pos=sSrc.find(sOld, pos)) != string::npos)
	{
		sSrc.replace(pos, lenOld, sNew);//替换字符串
		pos += lenNew;
	}
}
Example #7
0
bool LogWriter::open(string filename, double timestamp) {
  int pos = filename.find(placeholder);
  if (pos != string::npos)
    filename.replace(pos, placeholder.length(),
      Timestamp::toString(timestamp));

  if (logFilename != filename)
    return open(filename);
  else
    return isOpen();
}
Example #8
0
//----------------------------------------------------------------------------
//replaces all punctuation (except apostrophes) with spaces 
string removePunct(string s)
{
	for(int i = 0; i != s.length(); i++)
	{
		if(ispunct(s[i]) && s[i] !=  '\'')
		{
			s.replace(i, 1, " ");
		}
	}
	return s;
}
void CShoshTreeCtrl::Myreplace(string &str,string oldstr,string newstr) 
{  
	int pos=string::npos; 
	int start_index=0;  
	int old_str_len=oldstr.size(),new_str_len=new_str_len=newstr.size(); 
	while((pos=str.find(oldstr,start_index))!=string::npos) 
	{  
		str.replace(pos,old_str_len,newstr); 
		start_index=pos+new_str_len; 
	} 
}  
Example #10
0
/// If token is contained in phrase, replaces token with value.
void ReplaceToken(string &phrase, string &token, string &value)
{
  // find token
  size_t index = phrase.find(token);

  if (index == string::npos)
    return; // not found

  // replace token
  phrase.replace(index, token.size(), value);
}
Example #11
0
// Remove non-number characters
string remove_non_number( string str )
{
    string number_mask = "0123456789-.abcdefpxABCDEFPX";
    size_t found = str.find_first_not_of(number_mask);
    while (found != string::npos) {
        //str[found]='*';
        str.replace(found, 1, "");
        found = str.find_first_not_of(number_mask);
    }
    return str;
}
Example #12
0
void OutgoingRoap::replaceAll(string& str, const char* find, const char* replace)
{
  size_t position = 0;
  
  while ((position = str.find(find, position)) != string::npos)
  {
    CSFLogDebugS(logTag, "Found one - " << replace);
    str.replace(position, strlen(find), replace);
    position += strlen(find);
  }
}
Example #13
0
void replacefun(string &s, string const& oldVal, string const& newVal)
{
	for(size_t pos=0; pos<s.size()-oldVal.size();)
	{
		if(s[pos] == oldVal[0] && s.substr(pos,oldVal.size())== oldVal)
			s.replace(pos, oldVal.size(), newVal),
			pos += newVal.size();
		else
			++pos;
	}
}
Example #14
0
	void ASPVariableQuery::replaceFittingPredicate(string& ruleBody, string predicate)
	{
		auto tmp = predicate.substr(0, predicate.find("("));
		auto pos = ruleBody.find(tmp);
		if (pos != string::npos)
		{
			stringstream ss;
			ss << this->queryProgramSection << "(" << tmp << "("
					<< ruleBody.substr(pos + tmp.size() + 1, ruleBody.find(")", pos) - pos - tmp.size() - 1) << "))";
			ruleBody.replace(pos, ruleBody.find(")", pos) - pos + 1, ss.str());
		}
	}
Example #15
0
// Quick and easy simple global search and replace.
static bool replace(string& str, const string& from, const string& to)
{
    size_t start_pos = str.find(from);
    if(start_pos == std::string::npos)
        return false;
    while(start_pos != std::string::npos)
    {
        str.replace(start_pos, from.length(), to);
        start_pos = str.find(from,start_pos+to.length());
    }
    return true;
}
Example #16
0
void replaceAll(string &s, const char *from, const char *to) {
  assert(from && *from);
  assert(to);

  string::size_type lenFrom = strlen(from);
  string::size_type lenTo = strlen(to);
  for (string::size_type pos = s.find(from);
       pos != string::npos;
       pos = s.find(from, pos + lenTo)) {
    s.replace(pos, lenFrom, to);
  }
}
Example #17
0
/*
*	return size() == 0 if hier's format is wrong
*
*/
vector<ULL> Tracker::parseHier(string hier){
	vector<ULL> ret;
	int index;
	if (hier.find_first_not_of("0123456789.") != string::npos)
		return ret;
	if (hier.at(0) == '.')
		ret.push_back(0);	// absoluted path
	else
		ret.push_back(1);	// related path
	while(hier.size() > 0){
		index = hier.find_first_of(".");
		if (index == 0)
			hier.replace(0, 1, "");
		else{
			string seg = hier.substr(0, index);
			ret.push_back(atoi(seg.c_str()));
			hier.replace(0, index, "");
		}
	}
	return ret;
}
Example #18
0
void StringReplace(string &strBase, string strSrc, string strDes)  
{  
	string::size_type pos = 0;  
	string::size_type srcLen = strSrc.size();  
	string::size_type desLen = strDes.size();  
	pos=strBase.find(strSrc, pos);   
	while ((pos != string::npos))  
	{  
		strBase.replace(pos, srcLen, strDes);  
		pos=strBase.find(strSrc, (pos+desLen));  
	}  
} 
const char*
_TParamDef::param_name_suffix( const char* inName, long inSuffix )
{
  static string s;
  s = inName;
  ostringstream os;
  os << inSuffix;
  unsigned int i = s.find( RUNTIME_SUFFIX );
  assert( i != string::npos );
  s.replace( i, sizeof( RUNTIME_SUFFIX ) - 1, os.str() );
  return s.c_str();
}
Example #20
0
//find a string in a string and replace with a string
int inline ProjectManager::findAndReplace(string& source, const string& find, const string& replace)
{
    int num=0;
    int fLen = find.size();
    int rLen = replace.size();
    for (unsigned int pos=0; (pos=source.find(find, pos))!=string::npos; pos+=rLen)
    {
        num++;
        source.replace(pos, fLen, replace);
    }
    return num;
}
Example #21
0
	string replaceSpace(string str) {
		int i = 0;
		while(i < str.size()) {
			if(str[i] == ' ') {
				str.replace(i, 1, "%20");
				i += 3;
			} else {
				++i;
			}
		}
		return str;
	}
Example #22
0
std::vector<std::string> getElements(string value)
{
    size_t index = 0;
    while (true) {
        index = value.find("  ", 0);
        if (index == string::npos)
            break;
        value.replace(index, 2, " ");
    }
    vector<string> elements = splitString(value, ' ');
    return elements;
}
Example #23
0
string replaceValue(string cont, string key, string value) {
    int pos = cont.find(key + ":");
    string newValue = key + ":" + value + ";\n";
    if (pos != cont.npos) {
        int end = cont.find(";", pos) + 2; //; and \n
        cont = cont.replace(pos, end - pos, newValue);
    } else {
        cont = cont.append(newValue);
    }

    return cont;
}
Example #24
0
string StringTools::ReplaceAll(string& strExpression, const string& strFind, const string& strReplace)
{
    size_t len;
    size_t pos;

    len = strFind.length();

	while((pos=strExpression.find(strFind)) != string::npos)
        strExpression.replace(pos, len, strReplace);

    return strExpression;
}
bool isNumeric(string line)
{
    char* p;
    int i = line.find_first_of(".");
    while (i != -1)
    {
        line = line.replace(i, 1, "0");
        i = line.find_first_of(".");
    }
    strtol(line.c_str(), &p, 10);
    return *p == 0;
}
void cGlobals::ReplaceStringVars(string &value) {
    for (map<string,string>::iterator it = stringVars.begin(); it != stringVars.end(); it++) {
        stringstream sToken;
        sToken << "{" << it->first << "}";
        string token = sToken.str();
        size_t foundToken = value.find(token);
        if (foundToken != string::npos) {
            value = value.replace(foundToken, token.size(), it->second);
        }
    }

}
Example #27
0
// 由于被替换的内容可能包含?号,所以需要更新开始搜寻的位置信息来避免替换刚刚插入的?号
void replace_mark(string& str, string& new_value, uint32_t& begin_pos)
{
    string::size_type pos = str.find('?', begin_pos);
    if (pos == string::npos) {
        return;
    }
    
    string prime_new_value = "'"+ new_value + "'";
    str.replace(pos, 1, prime_new_value);
    
    begin_pos = pos + prime_new_value.size();
}
Example #28
0
//
// Remove from the last found char in a string to the beginning
//
bool string_rremove_to_start (string &in, const string c)
{
    string::size_type at = 0;

    at = in.rfind(c, string::npos);
        
    if (at != string::npos) {
        in.replace(0, at + c.size(), "", 0);
        return (true);
    }
    return (false);
}
Example #29
0
uint32_t svStorageEngine::PrepareSQL(
	string &sql, const char *token, const string &value)
{
	uint32_t matches = 0;
	size_t pos = sql.find(token);
	while (pos != string::npos) {
		matches++;
		sql.replace(pos, strlen(token), value);
		pos = sql.find(token, pos + strlen(token));
	}
	return matches;
}
Example #30
0
//
// Remove from the first found char in a string to the end
//
bool string_remove_to_end (string &in, const char c)
{
    string::size_type at = 0;

    at = in.find(c, 0);
        
    if (at != string::npos) {
        in.replace(at, in.size() - at, "", 0);
        return (true);
    }
    return (false);
}