-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tag: consider tag rule on get matched rules
- Loading branch information
Showing
7 changed files
with
96 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "TagKeeper.hpp" | ||
|
||
bool TagKeeper::isTagged(const std::string& tag, bool strict) { | ||
return m_tags.contains(tag) || (!strict && m_tags.contains(tag + "*")); | ||
} | ||
|
||
bool TagKeeper::applyTag(const std::string& tag, bool dynamic) { | ||
|
||
std::string tagReal = tag; | ||
|
||
if (dynamic && !tag.ends_with("*")) | ||
tagReal += "*"; | ||
|
||
bool changed = true; | ||
bool setTag = true; | ||
|
||
if (tagReal.starts_with("-")) { // unset | ||
tagReal = tagReal.substr(1); | ||
changed = isTagged(tagReal, true); | ||
setTag = false; | ||
} else if (tagReal.starts_with("+")) { // set | ||
tagReal = tagReal.substr(1); | ||
changed = !isTagged(tagReal, true); | ||
} else // toggle if without prefix | ||
setTag = !isTagged(tagReal, true); | ||
|
||
if (!changed) | ||
return false; | ||
|
||
if (setTag) | ||
m_tags.emplace(tagReal); | ||
else | ||
m_tags.erase(tagReal); | ||
|
||
return true; | ||
} | ||
|
||
bool TagKeeper::removeDynamicTags() { | ||
return std::erase_if(m_tags, [](const auto& tag) { return tag.ends_with("*"); }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <set> | ||
|
||
class TagKeeper { | ||
private: | ||
std::set<std::string> m_tags; | ||
|
||
public: | ||
bool isTagged(const std::string& tag, bool strict = false); | ||
bool applyTag(const std::string& tag, bool dynamic = false); | ||
bool removeDynamicTags(); | ||
|
||
inline const auto& getTags() { | ||
return m_tags; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters