diff options
author | Alexander Tkachev | 2016-07-06 15:37:13 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 627bda9d82c178641e5b5253379c21ce556eb3c2 (patch) | |
tree | fd82f68f1380450bee225f6b0adf62eff2894f15 | |
parent | e47b6c04b30565b1db238c2784e562f3f4472d70 (diff) | |
download | scummvm-rg350-627bda9d82c178641e5b5253379c21ce556eb3c2.tar.gz scummvm-rg350-627bda9d82c178641e5b5253379c21ce556eb3c2.tar.bz2 scummvm-rg350-627bda9d82c178641e5b5253379c21ce556eb3c2.zip |
COMMON: Add replace(String, String, String)
Searches for a substring in the string and replaces it with the other
string.
-rw-r--r-- | backends/networking/sdl_net/indexpagehandler.cpp | 9 | ||||
-rw-r--r-- | backends/networking/sdl_net/indexpagehandler.h | 1 | ||||
-rw-r--r-- | common/str.cpp | 9 | ||||
-rw-r--r-- | common/str.h | 9 |
4 files changed, 18 insertions, 10 deletions
diff --git a/backends/networking/sdl_net/indexpagehandler.cpp b/backends/networking/sdl_net/indexpagehandler.cpp index c44c3d4a5a..b3790a8393 100644 --- a/backends/networking/sdl_net/indexpagehandler.cpp +++ b/backends/networking/sdl_net/indexpagehandler.cpp @@ -249,15 +249,6 @@ Common::String IndexPageHandler::code() { return _code; } /// utils -void IndexPageHandler::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); - } -} - Common::Archive *IndexPageHandler::getZipArchive() { // first search in themepath if (ConfMan.hasKey("themepath")) { diff --git a/backends/networking/sdl_net/indexpagehandler.h b/backends/networking/sdl_net/indexpagehandler.h index 0ccbf32480..a75c7a0381 100644 --- a/backends/networking/sdl_net/indexpagehandler.h +++ b/backends/networking/sdl_net/indexpagehandler.h @@ -61,7 +61,6 @@ class IndexPageHandler: public GUI::CommandSender { */ bool transformPath(Common::String &path, Common::String &prefixToRemove, Common::String &prefixToAdd); - void replace(Common::String &source, const Common::String &what, const Common::String &with); Common::Archive *getZipArchive(); Common::ArchiveMemberList listArchive(); Common::SeekableReadStream *getArchiveFile(Common::String name); 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 |