MCPcopy Create free account
hub / github.com/Alexays/Waybar / rewriteString

Function rewriteString

src/util/rewrite_string.cpp:8–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7namespace waybar::util {
8std::string rewriteString(const std::string& value, const Json::Value& rules) {
9 if (!rules.isObject()) {
10 return value;
11 }
12
13 std::string res = value;
14
15 for (auto it = rules.begin(); it != rules.end(); ++it) {
16 if (it.key().isString() && it->isString()) {
17 try {
18 // malformated regexes will cause an exception.
19 // in this case, log error and try the next rule.
20 const std::regex rule{it.key().asString(), std::regex_constants::icase};
21 if (std::regex_match(value, rule)) {
22 res = std::regex_replace(res, rule, it->asString());
23 }
24 } catch (const std::regex_error& e) {
25 spdlog::error("Invalid rule {}: {}", it.key().asString(), e.what());
26 }
27 }
28 }
29
30 return res;
31}
32} // namespace waybar::util

Callers 6

updateMethod · 0.85
update_icon_labelMethod · 0.85
doUpdateMethod · 0.85
updateMethod · 0.85
updateMethod · 0.85
handle_frameMethod · 0.85

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected