summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-05-10 14:35:55 (GMT)
committerBrad King <brad.king@kitware.com>2016-05-10 17:28:37 (GMT)
commitc9228c37f05af96e5ac5c62a344a58b47deeed20 (patch)
tree12a27269181cf1e2fe39d56db0ad5bcba9e4d422 /src
parent41581dbb55b7df7f72b5c8e03d116c2663d2da1c (diff)
downloadCastXML-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.cxx11
-rw-r--r--src/Utils.h4
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