summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx36
1 files changed, 25 insertions, 11 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 70d0d96..0b887fc 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -252,23 +252,37 @@ void SystemTools::ReplaceString(kwsys_std::string& source,
const char* replace,
const char* with)
{
+ const char *src = source.c_str();
+ char *searchPos = strstr(src,replace);
+
// get out quick if string is not found
- kwsys_std::string::size_type start = source.find(replace);
- if(start == kwsys_std::string::npos)
+ if (!searchPos)
{
return;
}
- kwsys_std::string rest;
- kwsys_std::string::size_type lengthReplace = strlen(replace);
- kwsys_std::string::size_type lengthWith = strlen(with);
- while(start != kwsys_std::string::npos)
- {
- rest = source.substr(start+lengthReplace);
- source = source.substr(0, start);
+
+ // perform replacements until done
+ size_t replaceSize = strlen(replace);
+ char *orig = strdup(src);
+ char *currentPos = orig;
+ searchPos = searchPos - src + orig;
+
+ // initialize the result
+ source.clear();
+ do
+ {
+ *searchPos = '\0';
+ source += currentPos;
+ currentPos = searchPos + replaceSize;
+ // replace
source += with;
- source += rest;
- start = source.find(replace, start + lengthWith );
+ searchPos = strstr(currentPos,replace);
}
+ while (searchPos);
+
+ // copy any trailing text
+ source += currentPos;
+ free(orig);
}
// Read a registry value.