diff --git a/source/code/common.cpp b/source/code/common.cpp index 8dedc20..202361a 100644 --- a/source/code/common.cpp +++ b/source/code/common.cpp @@ -77,6 +77,22 @@ std::vector split_string(const std::string& input, const std::strin return out; } +void replace_all(std::string& inout, const char* find_text, const char* replacement_text) +{ + const std::size_t find_len = std::strlen(find_text); + if (find_len == 0) + { + return; //would loop forever + } + const std::size_t repl_len = std::strlen(replacement_text); + + std::size_t pos = 0; + while ((pos = inout.find(find_text, pos, find_len)) != std::string::npos) { + inout.replace(pos, find_len, replacement_text, repl_len); + pos += repl_len; // skip past the insert + } +} + /** * Takes a number of milliseconds and returns the value in commonTime format. */ diff --git a/source/code/common.h b/source/code/common.h index e02d30e..e5dfddd 100644 --- a/source/code/common.h +++ b/source/code/common.h @@ -75,6 +75,14 @@ double str2double(const std::string &str2parse) __attribute__((const)); */ std::vector split_string(const std::string& input, const std::string& sep); +/** + * Does search and replace in a string. + * @param inout the string to modify + * @param find_text the text to find + * @param replacement_text the text to replace with + */ +void replace_all(std::string& inout, const char* find_text, const char* replacement_text); + class TimeHandler { public: diff --git a/source/code/os.cpp b/source/code/os.cpp index cb1c527..77e0ece 100644 --- a/source/code/os.cpp +++ b/source/code/os.cpp @@ -32,7 +32,6 @@ https://blockattack.net #include #include #endif -#include #include static sago::PlatformFolders pf; @@ -123,7 +122,7 @@ void OsCreateFolder(const std::string& path) { //Now for Windows Vista+ std::vector element_vector; std::string new_path = path; - boost::replace_all(new_path, "/", "\\"); + replace_all(new_path, "/", "\\"); size_t pos = new_path.find("\\"); while ( pos != std::string::npos) { std::string part_of_path = new_path.substr(0, pos);