Skip to content

Commit

Permalink
Merge pull request #185 from matt439/fix-replace-all
Browse files Browse the repository at this point in the history
Fix bug in replace_all
  • Loading branch information
macite authored Oct 18, 2024
2 parents aece11b + de8be75 commit 137488c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions coresdk/src/coresdk/basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions coresdk/src/test/test_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> vec = split(mixedText, ' ');

Expand Down

0 comments on commit 137488c

Please sign in to comment.