diff options
author | Brad King <brad.king@kitware.com> | 2016-05-10 14:35:55 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-10 17:28:37 (GMT) |
commit | c9228c37f05af96e5ac5c62a344a58b47deeed20 (patch) | |
tree | 12a27269181cf1e2fe39d56db0ad5bcba9e4d422 /src | |
parent | 41581dbb55b7df7f72b5c8e03d116c2663d2da1c (diff) | |
download | CastXML-c9228c37f05af96e5ac5c62a344a58b47deeed20.zip CastXML-c9228c37f05af96e5ac5c62a344a58b47deeed20.tar.gz CastXML-c9228c37f05af96e5ac5c62a344a58b47deeed20.tar.bz2 |
Utils: Add a function to perform string replacement
Diffstat (limited to 'src')
-rw-r--r-- | src/Utils.cxx | 11 | ||||
-rw-r--r-- | src/Utils.h | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/Utils.cxx b/src/Utils.cxx index 400b563..cea0655 100644 --- a/src/Utils.cxx +++ b/src/Utils.cxx @@ -214,6 +214,17 @@ std::string encodeXML(std::string const& in, bool cdata) return xml; } +//---------------------------------------------------------------------------- +std::string stringReplace(std::string str, std::string const& in, + std::string const& out) { + std::string::size_type p = 0; + while ((p = str.find(in, p)) != std::string::npos) { + str.replace(p, in.size(), out); + p += out.length(); + } + return str; +} + #if defined(_WIN32) # include <windows.h> #endif diff --git a/src/Utils.h b/src/Utils.h index 1baeb33..7103fa7 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -47,4 +47,8 @@ void suppressInteractiveErrors(); /// encodeXML - Convert character string to XML representation std::string encodeXML(std::string const& in, bool cdata = false); +/// stringReplace - Replace all occurrences of an 'in' string with 'out'. +std::string stringReplace(std::string str, std::string const& in, + std::string const& out); + #endif // CASTXML_UTILS_H |