Add .clang-format and apply it
This commit is contained in:
@@ -9,8 +9,10 @@
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
struct Matcher {
|
||||
void add_rule(std::string const &s) {
|
||||
struct Matcher
|
||||
{
|
||||
void add_rule(std::string const& s)
|
||||
{
|
||||
std::size_t len = 0;
|
||||
unsigned long id = std::stoul(s, &len);
|
||||
assert(s[len] == ':');
|
||||
@@ -26,24 +28,25 @@ struct Matcher {
|
||||
|
||||
void calculate_regex() { re_.assign("^" + expand_rule(0) + "$"); }
|
||||
|
||||
bool does_match(std::string const &s) const {
|
||||
return std::regex_match(s, re_);
|
||||
}
|
||||
bool does_match(std::string const& s) const { return std::regex_match(s, re_); }
|
||||
|
||||
private:
|
||||
std::string expand_rule(std::size_t id) {
|
||||
std::string expand_rule(std::size_t id)
|
||||
{
|
||||
std::string re;
|
||||
std::string const &rule = rules_[id];
|
||||
std::string const& rule = rules_[id];
|
||||
std::size_t pos = 0;
|
||||
bool needs_brackets = false;
|
||||
while (pos < rule.size()) {
|
||||
if (rule[pos] == ' ') {
|
||||
++pos;
|
||||
} else if (rule[pos] == '|') {
|
||||
}
|
||||
else if (rule[pos] == '|') {
|
||||
re += "|";
|
||||
needs_brackets = true;
|
||||
++pos;
|
||||
} else if (rule[pos] == '"') {
|
||||
}
|
||||
else if (rule[pos] == '"') {
|
||||
++pos;
|
||||
while (pos < rule.size() && rule[pos] != '"') {
|
||||
re += rule[pos];
|
||||
@@ -52,12 +55,14 @@ private:
|
||||
assert(pos < rule.size());
|
||||
assert(rule[pos] == '"');
|
||||
++pos;
|
||||
} else if (std::isdigit(rule[pos])) {
|
||||
}
|
||||
else if (std::isdigit(rule[pos])) {
|
||||
std::size_t len = 0;
|
||||
std::size_t subid = std::stoul(rule.substr(pos), &len);
|
||||
pos += len;
|
||||
re += expand_rule(subid);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@@ -73,7 +78,8 @@ private:
|
||||
std::regex re_;
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
std::string line;
|
||||
Matcher matcher;
|
||||
bool adding_rules = true;
|
||||
@@ -82,9 +88,11 @@ int main(void) {
|
||||
if (line.empty()) {
|
||||
adding_rules = false;
|
||||
matcher.calculate_regex();
|
||||
} else if (adding_rules) {
|
||||
}
|
||||
else if (adding_rules) {
|
||||
matcher.add_rule(line);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
bool m = matcher.does_match(line);
|
||||
std::cout << line << ": does " << (m ? "" : "not ") << "match\n";
|
||||
matches += m;
|
||||
|
Reference in New Issue
Block a user