From a28f68968c8138bc13731fceb2edea14a9157a7d Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 17 Apr 2020 14:19:56 -0700 Subject: [PATCH] Add replace_all() This is just a function that will be used in the optimized tag-finding function. --- desktop_version/src/editor.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 3c5da840..0b9d6376 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -86,6 +86,22 @@ bool compare_nocase (std::string first, std::string second) return false; } +void replace_all(std::string& str, const std::string& from, const std::string& to) +{ + if (from.empty()) + { + return; + } + + size_t start_pos = 0; + + while ((start_pos = str.find(from, start_pos)) != std::string::npos) + { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); //In case `to` contains `from`, like replacing 'x' with 'yx' + } +} + void editorclass::getDirectoryData() {