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

Method RegexCollection

src/util/regex_collection.cpp:13–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11int default_priority_function(std::string& key) { return 0; }
12
13RegexCollection::RegexCollection(const Json::Value& map, std::string default_repr,
14 const std::function<int(std::string&)>& priority_function)
15 : default_repr(std::move(default_repr)) {
16 if (!map.isObject()) {
17 spdlog::warn("Mapping is not an object");
18 return;
19 }
20
21 for (auto it = map.begin(); it != map.end(); ++it) {
22 if (it.key().isString() && it->isString()) {
23 std::string key = it.key().asString();
24 int priority = priority_function(key);
25 try {
26 const std::regex rule{key, std::regex_constants::icase};
27 rules.emplace_back(rule, it->asString(), priority);
28 } catch (const std::regex_error& e) {
29 spdlog::error("Invalid rule '{}': {}", key, e.what());
30 }
31 }
32 }
33
34 std::sort(rules.begin(), rules.end(), [](Rule& a, Rule& b) { return a.priority > b.priority; });
35}
36
37std::string RegexCollection::find_match(std::string& value, bool& matched_any) {
38 for (auto& rule : rules) {

Callers

nothing calls this directly

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected