aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/str.cpp9
-rw-r--r--common/str.h9
2 files changed, 18 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 326b4a80d1..90bd539790 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -838,6 +838,15 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod
}
}
+void replace(Common::String &source, const Common::String &what, const Common::String &with) {
+ const char *cstr = source.c_str();
+ const char *position = strstr(cstr, what.c_str());
+ if (position) {
+ uint32 index = position - cstr;
+ source.replace(index, what.size(), with);
+ }
+}
+
String tag2string(uint32 tag) {
char str[5];
str[0] = (char)(tag >> 24);
diff --git a/common/str.h b/common/str.h
index 89b832d57e..1293d89508 100644
--- a/common/str.h
+++ b/common/str.h
@@ -390,6 +390,15 @@ String normalizePath(const String &path, const char sep);
*/
bool matchString(const char *str, const char *pat, bool ignoreCase = false, bool pathMode = false);
+/**
+ * Function which replaces substring with the other. It happens in place.
+ * If there is no substring found, original string is not changed.
+ *
+ * @param source String to search and replace substring in.
+ * @param what Substring to replace.
+ * @param with String to replace with.
+ */
+void replace(Common::String &source, const Common::String &what, const Common::String &with);
/**
* Take a 32 bit value and turn it into a four character string, where each of