diff --git a/src/renderer/widgets/IWidget.cpp b/src/renderer/widgets/IWidget.cpp index 0cb8f93..f6ef001 100644 --- a/src/renderer/widgets/IWidget.cpp +++ b/src/renderer/widgets/IWidget.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include using namespace Hyprutils::String; @@ -48,16 +49,6 @@ Vector2D IWidget::posFromHVAlign(const Vector2D& viewport, const Vector2D& size, return pos; } -static void replaceAll(std::string& str, const std::string& from, const std::string& to) { - if (from.empty()) - return; - size_t pos = 0; - while ((pos = str.find(from, pos)) != std::string::npos) { - str.replace(pos, from.length(), to); - pos += to.length(); - } -} - static void replaceAllAttempts(std::string& str) { const size_t ATTEMPTS = g_pHyprlock->getPasswordFailedAttempts(); @@ -133,29 +124,29 @@ IWidget::SFormatResult IWidget::formatString(std::string in) { Debug::log(WARN, "Error in formatString, user_gecos null. Errno: ", errno); IWidget::SFormatResult result; - replaceAll(in, "$DESC", std::string{user_gecos ? user_gecos : ""}); - replaceAll(in, "$USER", std::string{username ? username : ""}); - replaceAll(in, "
", std::string{"\n"}); + replaceInString(in, "$DESC", std::string{user_gecos ? user_gecos : ""}); + replaceInString(in, "$USER", std::string{username ? username : ""}); + replaceInString(in, "
", std::string{"\n"}); if (in.contains("$TIME12")) { - replaceAll(in, "$TIME12", getTime12h()); + replaceInString(in, "$TIME12", getTime12h()); result.updateEveryMs = result.updateEveryMs != 0 && result.updateEveryMs < 1000 ? result.updateEveryMs : 1000; } if (in.contains("$TIME")) { - replaceAll(in, "$TIME", getTime()); + replaceInString(in, "$TIME", getTime()); result.updateEveryMs = result.updateEveryMs != 0 && result.updateEveryMs < 1000 ? result.updateEveryMs : 1000; } if (in.contains("$FAIL")) { const auto FAIL = g_pAuth->getLastFailText(); - replaceAll(in, "$FAIL", FAIL.has_value() ? FAIL.value() : ""); + replaceInString(in, "$FAIL", FAIL.has_value() ? FAIL.value() : ""); result.allowForceUpdate = true; } if (in.contains("$PROMPT")) { const auto PROMPT = g_pAuth->getLastPrompt(); - replaceAll(in, "$PROMPT", PROMPT.has_value() ? PROMPT.value() : ""); + replaceInString(in, "$PROMPT", PROMPT.has_value() ? PROMPT.value() : ""); result.allowForceUpdate = true; } diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index 0843822..5783b36 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -2,17 +2,10 @@ #include "../Renderer.hpp" #include "../../core/hyprlock.hpp" #include "../../core/Auth.hpp" +#include #include -static void replaceAll(std::string& str, const std::string& from, const std::string& to) { - if (from.empty()) - return; - size_t pos = 0; - while ((pos = str.find(from, pos)) != std::string::npos) { - str.replace(pos, from.length(), to); - pos += to.length(); - } -} +using namespace Hyprutils::String; CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::unordered_map& props, const std::string& output) : outputStringPort(output), shadow(this, props, viewport_) { @@ -325,11 +318,11 @@ void CPasswordInputField::updatePlaceholder() { if (displayFail) { g_pHyprlock->addTimer(std::chrono::milliseconds(configFailTimeoutMs), failTimeoutCallback, nullptr); placeholder.currentText = configFailText; - replaceAll(placeholder.currentText, "$FAIL", AUTHFEEDBACK); - replaceAll(placeholder.currentText, "$ATTEMPTS", std::to_string(placeholder.failedAttempts)); + replaceInString(placeholder.currentText, "$FAIL", AUTHFEEDBACK); + replaceInString(placeholder.currentText, "$ATTEMPTS", std::to_string(placeholder.failedAttempts)); } else { placeholder.currentText = configPlaceholderText; - replaceAll(placeholder.currentText, "$PROMPT", AUTHFEEDBACK); + replaceInString(placeholder.currentText, "$PROMPT", AUTHFEEDBACK); } placeholder.resourceID =