Move replaceAll() to utility

This commit is contained in:
WarmUpTill 2023-02-22 15:03:48 +01:00 committed by WarmUpTill
parent 3d6d690583
commit 0bf70e443e
3 changed files with 15 additions and 13 deletions

View File

@ -1042,3 +1042,16 @@ std::pair<int, int> 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();
}
}

View File

@ -118,3 +118,4 @@ QString formatJsonString(QString);
QString escapeForRegex(QString &s);
bool doubleEquals(double left, double right, double epsilon);
std::pair<int, int> getCursorPos();
void replaceAll(std::string &str, const std::string &from, const std::string &to);

View File

@ -1,4 +1,5 @@
#include "variable.hpp"
#include "utility.hpp"
#include <switcher-data-structs.hpp>
@ -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) {