From 0bf70e443ee125aeb836706a8e3e223c595fa052 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Wed, 22 Feb 2023 15:03:48 +0100 Subject: [PATCH] Move replaceAll() to utility --- src/utils/utility.cpp | 13 +++++++++++++ src/utils/utility.hpp | 1 + src/utils/variable.cpp | 14 +------------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/utils/utility.cpp b/src/utils/utility.cpp index 486b4e9c..ffa44951 100644 --- a/src/utils/utility.cpp +++ b/src/utils/utility.cpp @@ -1042,3 +1042,16 @@ std::pair getCursorPos() auto cursorPos = QCursor::pos(); return {cursorPos.x(), cursorPos.y()}; } + +void replaceAll(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(); + } +} diff --git a/src/utils/utility.hpp b/src/utils/utility.hpp index 6540731e..688a7ce7 100644 --- a/src/utils/utility.hpp +++ b/src/utils/utility.hpp @@ -118,3 +118,4 @@ QString formatJsonString(QString); QString escapeForRegex(QString &s); bool doubleEquals(double left, double right, double epsilon); std::pair getCursorPos(); +void replaceAll(std::string &str, const std::string &from, const std::string &to); diff --git a/src/utils/variable.cpp b/src/utils/variable.cpp index 65f838e7..1c7a2f94 100644 --- a/src/utils/variable.cpp +++ b/src/utils/variable.cpp @@ -1,4 +1,5 @@ #include "variable.hpp" +#include "utility.hpp" #include @@ -160,19 +161,6 @@ const char *VariableResolvingString::c_str() const return _resolvedValue.c_str(); } -static void replaceAll(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(); - } -} - std::string SubstitueVariables(std::string str) { for (const auto &v : switcher->variables) {