当前位置: 首页>>代码示例>>C++>>正文


C++ string::insert方法代码示例

本文整理汇总了C++中std::string::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ string::insert方法的具体用法?C++ string::insert怎么用?C++ string::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::string的用法示例。


在下文中一共展示了string::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ProtectString

/***********************************************************
protect part of the string containing character [
***********************************************************/
void ChatBox::ProtectString(std::string &text)
{
	size_t pos=text.find("[");
	while(pos != std::string::npos)
	{
		if((text.size() > pos+2) && ((text[pos+1] == 'c' && text[pos+2] == 'o') || (text[pos+1] == 'i' && text[pos+2] == 'm')))
			pos=text.find("[", pos+1);	
		else
		{
			text.insert(pos, "\\"	);
			pos=text.find("[", pos+2);	
		}
	}
}
开发者ID:leloulight,项目名称:lbanet,代码行数:17,代码来源:ChatBox.cpp

示例2: changeFrameNumber

void SHelper::changeFrameNumber(std::string& res, int frame)
{
	int first = res.find('.', 0);
	if(first < 0) return;
		
	int last = res.rfind('.', res.size());
	if(last < 0) return;
	
	char mid[8];
	sprintf(mid, ".%d.", frame);
	
	res.erase(first, last-first+1);
	res.insert(first, mid);
}
开发者ID:kkaushalp,项目名称:aphid,代码行数:14,代码来源:SHelper.cpp

示例3: changetoknth

bool changetoknth(std::string &str, int n, const char *with, bool insert = false, bool nonzero = false)
{
    std::string::size_type s = 0, e = 0;
    if (!findtoknth(str, n, s, e))
        return false;
    if (nonzero && str.substr(s, e-s) == "0")
        return true;                                        // not an error
    if (!insert)
        str.replace(s, e-s, with);
    else
        str.insert(s, with);

    return true;
}
开发者ID:DragonFire,项目名称:TRcore,代码行数:14,代码来源:PlayerDump.cpp

示例4: if

void SHelper::changeFrameNumberFistDot4Digit(std::string& res, int frame)
{
	int first = res.find('.', 0);
	if(first < 0) return;
	
	char mid[8];
	if(frame<10) sprintf(mid, ".000%d.", frame);
	else if(frame<100) sprintf(mid, ".00%d.", frame);
	else if(frame<1000) sprintf(mid, ".0%d.", frame);
	else sprintf(mid, ".%d.", frame);
	
	res.erase(first, 6);
	res.insert(first, mid);
}
开发者ID:kkaushalp,项目名称:aphid,代码行数:14,代码来源:SHelper.cpp

示例5: StrSearchReplace

void StrSearchReplace( std::string &s, const std::string &to_find, const std::string& repl_with )
{
	std::string::size_type location = s.find(to_find);
	if ( location == std::string::npos )
	{
		return;
	}
	while ( location != std::string::npos )
	{
		s.erase(location,to_find.size());
		s.insert(location,repl_with);
		location = s.find(to_find, location);
	}
}
开发者ID:UkCvs,项目名称:commando,代码行数:14,代码来源:helper.cpp

示例6: expandTabs

void TextDiagnostic::expandTabs(std::string &SourceLine,
                                std::string &CaretLine) {
    // Scan the source line, looking for tabs.  If we find any, manually expand
    // them to spaces and update the CaretLine to match.
    for (unsigned i = 0; i != SourceLine.size(); ++i) {
        if (SourceLine[i] != '\t') continue;

        // Replace this tab with at least one space.
        SourceLine[i] = ' ';

        // Compute the number of spaces we need to insert.
        unsigned TabStop = DiagOpts.TabStop;
        assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop &&
               "Invalid -ftabstop value");
        unsigned NumSpaces = ((i+TabStop)/TabStop * TabStop) - (i+1);
        assert(NumSpaces < TabStop && "Invalid computation of space amt");

        // Insert spaces into the SourceLine.
        SourceLine.insert(i+1, NumSpaces, ' ');

        // Insert spaces or ~'s into CaretLine.
        CaretLine.insert(i+1, NumSpaces, CaretLine[i] == '~' ? '~' : ' ');
    }
}
开发者ID:avakar,项目名称:clang,代码行数:24,代码来源:TextDiagnostic.cpp

示例7: replace_beginning

bool replace_beginning(std::string &haystack, const std::string &needle, const std::string &newStr)
{
  bool replaced = false;

  // Locate the substring to replace
  size_t pos = haystack.find(needle);
  if(pos == std::string::npos) return false;
  if(pos != 0) return false;

  // Replace by erasing and inserting
  haystack.erase( pos, needle.length() );
  haystack.insert( pos, newStr );

  return true;
}
开发者ID:1974kpkpkp,项目名称:AviSynthPlus,代码行数:15,代码来源:strings.cpp

示例8: replaceDefines

static void replaceDefines(const std::string& compileTimeDefines, std::string& out)
{
    // Replace semicolons with '#define ... \n'
    if (compileTimeDefines.size() > 0)
    {
        size_t pos;
        out = compileTimeDefines;
        out.insert(0, "#define ");
        while ((pos = out.find(';')) != std::string::npos)
        {
            out.replace(pos, 1, "\n#define ");
        }
        out += "\n";
    }
}
开发者ID:RyunosukeOno,项目名称:rayjack,代码行数:15,代码来源:CCGLProgram.cpp

示例9: validate

	std::error_code validate(std::string& path)
	{
		if (path.empty())
			return std::make_error_code(std::errc::invalid_argument);

		if (path[0] == '/')
			return std::make_error_code(std::errc::invalid_argument);

		path.insert(0, "/");

		if (path[path.size() - 1] == '/')
			path = path.substr(0, path.size() - 1);

		return std::error_code();
	}
开发者ID:TwinkleStars,项目名称:x0,代码行数:15,代码来源:userdir.cpp

示例10: changenth

bool changenth(std::string& str, int n, const char* with, bool insert = false, bool nonzero = false)
{
    std::string::size_type s, e;
    if (!findnth(str, n, s, e))
        { return false; }

    if (nonzero && str.substr(s, e - s) == "0")
        { return true; }                                        // not an error
    if (!insert)
        { str.replace(s, e - s, with); }
    else
        { str.insert(s, with); }

    return true;
}
开发者ID:mangosthree,项目名称:server,代码行数:15,代码来源:PlayerDump.cpp

示例11: setColor

 void Message::setColor(std::string color)
 {
     color.insert((size_t)0, (size_t)(6 - color.size()), '0');
     int r = 0, g = 0, b = 0;
     
     r = strtol(color.substr(0, 2).c_str(), NULL, 16);
     g = strtol(color.substr(2, 2).c_str(), NULL, 16);        
     b = strtol(color.substr(4, 2).c_str(), NULL, 16);
     
     std::vector<int> v;
     v.push_back(r);
     v.push_back(g);
     v.push_back(b);
     this->setColor(v);
 }
开发者ID:Barrett17,项目名称:Caya,代码行数:15,代码来源:message.cpp

示例12:

// remove leading and trailing spaces and tabs (useful for copy/paste)
// also, if no protocol specified, add leading "sip:"
std::string
canonize_uri (std::string uri)
{
  const size_t begin_str = uri.find_first_not_of (" \t");
  if (begin_str == std::string::npos)  // there is no content
    return "";

  const size_t end_str = uri.find_last_not_of (" \t");
  const size_t range = end_str - begin_str + 1;
  uri = uri.substr (begin_str, range);
  const size_t pos = uri.find (":");
  if (pos == std::string::npos)
    uri = uri.insert (0, "sip:");
  return uri;
}
开发者ID:Klom,项目名称:ekiga,代码行数:17,代码来源:local-presentity.cpp

示例13: BroadcastString

//------------------------------------------------------------------------------
void BroadcastString(std::string& sStr, int sender)
{
   unsigned int len = sStr.length();
   MPI_Bcast(&len, 1, MPI_UNSIGNED, sender, MPI_COMM_WORLD);
   if (sStr.length() < len ) 
   {
      sStr.insert(sStr.end(),(size_t)(len-sStr.length()), ' ');
   }
   else if (sStr.length() > len ) 
   {
      sStr.erase( len,sStr.length()-len);
   }

   MPI_Bcast(const_cast<char *>(sStr.data()), len, MPI_CHAR, sender, MPI_COMM_WORLD);
}
开发者ID:Kasheftin,项目名称:DataProcessing,代码行数:16,代码来源:main_mpi.cpp

示例14: GET

bool HTTPClient::GET(const std::string &url, std::string &response, const bool bIgnoreNoDataReturned)
{
	response = "";
	std::vector<unsigned char> vHTTPResponse;
	std::vector<std::string> ExtraHeaders;
	if (!GETBinary(url,ExtraHeaders,vHTTPResponse))
		return false;
	if (!bIgnoreNoDataReturned)
	{
		if (vHTTPResponse.empty())
			return false;
	}
	response.insert( response.begin(), vHTTPResponse.begin(), vHTTPResponse.end() );
	return true;
}
开发者ID:blmpl,项目名称:domoticz,代码行数:15,代码来源:HTTPClient.cpp

示例15: quote_and_highlight

void regexmanager::quote_and_highlight(std::string& str, const std::string& location) {
	std::vector<regex_t *>& regexes = locations[location].first;

	unsigned int i = 0;
	for (auto regex : regexes) {
		if (!regex)
			continue;
		std::string initial_marker = extract_initial_marker(str);
		regmatch_t pmatch;
		unsigned int offset = 0;
		int err = regexec(regex, str.c_str(), 1, &pmatch, 0);
		while (err == 0) {
			// LOG(LOG_DEBUG, "regexmanager::quote_and_highlight: matched %s rm_so = %u rm_eo = %u", str.c_str() + offset, pmatch.rm_so, pmatch.rm_eo);
			std::string marker = utils::strprintf("<%u>", i);
			str.insert(offset + pmatch.rm_eo, std::string("</>") + initial_marker);
			// LOG(LOG_DEBUG, "after first insert: %s", str.c_str());
			str.insert(offset + pmatch.rm_so, marker);
			// LOG(LOG_DEBUG, "after second insert: %s", str.c_str());
			offset += pmatch.rm_eo + marker.length() + strlen("</>") + initial_marker.length();
			err = regexec(regex, str.c_str() + offset, 1, &pmatch, 0);
		}
		i++;
	}
}
开发者ID:Duncanla,项目名称:newsbeuter,代码行数:24,代码来源:regexmanager.cpp


注:本文中的std::string::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。