diff --git a/src/text.cpp b/src/text.cpp index bee2f52d2..f56dc7986 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -482,6 +482,22 @@ std::string ucFirst (const std::string& input) return output; } +//////////////////////////////////////////////////////////////////////////////// +const std::string str_replace ( + std::string &str, + const std::string& search, + const std::string& replacement) +{ + std::string::size_type pos = 0; + while ((pos = str.find (search, pos)) != std::string::npos) + { + str.replace (pos, search.length (), replacement); + pos += replacement.length (); + } + + return str; +} + //////////////////////////////////////////////////////////////////////////////// const char* optionalBlankLine () { diff --git a/src/text.h b/src/text.h index 8023e6014..a73734374 100644 --- a/src/text.h +++ b/src/text.h @@ -52,6 +52,7 @@ std::string commify (const std::string&); std::string lowerCase (const std::string&); std::string upperCase (const std::string&); std::string ucFirst (const std::string&); +const std::string str_replace (std::string&, const std::string&, const std::string&); const char* optionalBlankLine (); void guess (const std::string&, std::vector&, std::string&); bool nontrivial (const std::string&);