diff --git a/coresdk/src/coresdk/basics.cpp b/coresdk/src/coresdk/basics.cpp index 7716f04d..1a5967a8 100644 --- a/coresdk/src/coresdk/basics.cpp +++ b/coresdk/src/coresdk/basics.cpp @@ -76,6 +76,9 @@ namespace splashkit_lib string replace_all(const string &text, const string &substr, const string &replacement) { + if (substr.empty()) + return text; + string result = text; size_t pos = 0; while ((pos = result.find(substr, pos)) != string::npos) diff --git a/coresdk/src/test/test_text.cpp b/coresdk/src/test/test_text.cpp index a7628180..d2ec4c31 100644 --- a/coresdk/src/test/test_text.cpp +++ b/coresdk/src/test/test_text.cpp @@ -117,6 +117,7 @@ void test_string_utils() cout << "To lower of " << mixedText << " is " << to_lowercase(mixedText) << endl; cout << "Trim of " << mixedText << " is " << trim(mixedText) << endl; cout << "Replace all of " << mixedText << " is " << replace_all(mixedText, " ", "_") << endl; + cout << "Replace all of " << mixedText << " when substring is empty is " << replace_all(mixedText, "", "_") << endl; vector vec = split(mixedText, ' ');