|
5 | 5 | #include <chrono>
|
6 | 6 | #include <unistd.h>
|
7 | 7 | #include <pwd.h>
|
| 8 | +#include <hyprutils/string/String.hpp> |
8 | 9 | #include <hyprutils/string/VarList.hpp>
|
9 | 10 |
|
10 | 11 | using namespace Hyprutils::String;
|
@@ -48,16 +49,6 @@ Vector2D IWidget::posFromHVAlign(const Vector2D& viewport, const Vector2D& size,
|
48 | 49 | return pos;
|
49 | 50 | }
|
50 | 51 |
|
51 |
| -static void replaceAll(std::string& str, const std::string& from, const std::string& to) { |
52 |
| - if (from.empty()) |
53 |
| - return; |
54 |
| - size_t pos = 0; |
55 |
| - while ((pos = str.find(from, pos)) != std::string::npos) { |
56 |
| - str.replace(pos, from.length(), to); |
57 |
| - pos += to.length(); |
58 |
| - } |
59 |
| -} |
60 |
| - |
61 | 52 | static void replaceAllAttempts(std::string& str) {
|
62 | 53 |
|
63 | 54 | const size_t ATTEMPTS = g_pHyprlock->getPasswordFailedAttempts();
|
@@ -133,29 +124,29 @@ IWidget::SFormatResult IWidget::formatString(std::string in) {
|
133 | 124 | Debug::log(WARN, "Error in formatString, user_gecos null. Errno: ", errno);
|
134 | 125 |
|
135 | 126 | IWidget::SFormatResult result;
|
136 |
| - replaceAll(in, "$DESC", std::string{user_gecos ? user_gecos : ""}); |
137 |
| - replaceAll(in, "$USER", std::string{username ? username : ""}); |
138 |
| - replaceAll(in, "<br/>", std::string{"\n"}); |
| 127 | + replaceInString(in, "$DESC", std::string{user_gecos ? user_gecos : ""}); |
| 128 | + replaceInString(in, "$USER", std::string{username ? username : ""}); |
| 129 | + replaceInString(in, "<br/>", std::string{"\n"}); |
139 | 130 |
|
140 | 131 | if (in.contains("$TIME12")) {
|
141 |
| - replaceAll(in, "$TIME12", getTime12h()); |
| 132 | + replaceInString(in, "$TIME12", getTime12h()); |
142 | 133 | result.updateEveryMs = result.updateEveryMs != 0 && result.updateEveryMs < 1000 ? result.updateEveryMs : 1000;
|
143 | 134 | }
|
144 | 135 |
|
145 | 136 | if (in.contains("$TIME")) {
|
146 |
| - replaceAll(in, "$TIME", getTime()); |
| 137 | + replaceInString(in, "$TIME", getTime()); |
147 | 138 | result.updateEveryMs = result.updateEveryMs != 0 && result.updateEveryMs < 1000 ? result.updateEveryMs : 1000;
|
148 | 139 | }
|
149 | 140 |
|
150 | 141 | if (in.contains("$FAIL")) {
|
151 | 142 | const auto FAIL = g_pAuth->getLastFailText();
|
152 |
| - replaceAll(in, "$FAIL", FAIL.has_value() ? FAIL.value() : ""); |
| 143 | + replaceInString(in, "$FAIL", FAIL.has_value() ? FAIL.value() : ""); |
153 | 144 | result.allowForceUpdate = true;
|
154 | 145 | }
|
155 | 146 |
|
156 | 147 | if (in.contains("$PROMPT")) {
|
157 | 148 | const auto PROMPT = g_pAuth->getLastPrompt();
|
158 |
| - replaceAll(in, "$PROMPT", PROMPT.has_value() ? PROMPT.value() : ""); |
| 149 | + replaceInString(in, "$PROMPT", PROMPT.has_value() ? PROMPT.value() : ""); |
159 | 150 | result.allowForceUpdate = true;
|
160 | 151 | }
|
161 | 152 |
|
|
0 commit comments