Commit bab5b1f2 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

SystemTools: add string overload for ReplaceString

Change-Id: I5f0adcf5dc6013b7f643c99ec233ac76c622c4ac
parent 6cc24510
......@@ -701,8 +701,35 @@ bool SystemTools::MakeDirectory(const kwsys_stl::string& path)
// replace replace with with as many times as it shows up in source.
// write the result into source.
void SystemTools::ReplaceString(kwsys_stl::string& source,
const char* replace,
const char* with)
const kwsys_stl::string& replace,
const kwsys_stl::string& with)
{
// do while hangs if replaceSize is 0
if (replace.empty())
{
return;
}
SystemTools::ReplaceString(source, replace.c_str(), replace.size(), with);
}
void SystemTools::ReplaceString(kwsys_stl::string& source,
const char* replace,
const char* with)
{
// do while hangs if replaceSize is 0
if (!*replace)
{
return;
}
SystemTools::ReplaceString(source, replace, strlen(replace), with ? with : "");
}
void SystemTools::ReplaceString(kwsys_stl::string& source,
const char* replace,
size_t replaceSize,
const kwsys_stl::string& with)
{
const char *src = source.c_str();
char *searchPos = const_cast<char *>(strstr(src,replace));
......@@ -714,12 +741,6 @@ void SystemTools::ReplaceString(kwsys_stl::string& source,
}
// perform replacements until done
size_t replaceSize = strlen(replace);
// do while hangs if replaceSize is 0
if(replaceSize == 0)
{
return;
}
char *orig = strdup(src);
char *currentPos = orig;
searchPos = searchPos - src + orig;
......
......@@ -102,6 +102,9 @@ public:
static void ReplaceString(kwsys_stl::string& source,
const char* replace,
const char* with);
static void ReplaceString(kwsys_stl::string& source,
const kwsys_stl::string& replace,
const kwsys_stl::string& with);
/**
* Return a capitalized string (i.e the first letter is uppercased,
......@@ -907,6 +910,14 @@ private:
return &SystemToolsManagerInstance;
}
/**
* Actual implementation of ReplaceString.
*/
static void ReplaceString(kwsys_stl::string& source,
const char* replace,
size_t replaceSize,
const kwsys_stl::string& with);
/**
* Actual implementation of FileIsFullPath.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment