Add .clang-format and apply it

This commit is contained in:
2021-12-02 07:18:16 +00:00
parent e58dede1b6
commit cd5e2538df
103 changed files with 2714 additions and 2132 deletions

View File

@@ -8,7 +8,8 @@
#include <string>
#include <variant>
int do_parse(std::string const &s, std::string::size_type &pos) {
int do_parse(std::string const& s, std::string::size_type& pos)
{
int result = 0;
bool ignore = false;
@@ -16,16 +17,20 @@ int do_parse(std::string const &s, std::string::size_type &pos) {
if (s[pos] == '{') {
++pos;
result += do_parse(s, pos);
} else if (s[pos] == '[') {
}
else if (s[pos] == '[') {
++pos;
result += do_parse(s, pos);
} else if (s[pos] == '}') {
}
else if (s[pos] == '}') {
++pos;
return ignore ? 0 : result;
} else if (s[pos] == ']') {
}
else if (s[pos] == ']') {
++pos;
return result;
} else if (s[pos] == '"') {
}
else if (s[pos] == '"') {
++pos;
auto e = s.find('"', pos);
assert(e != std::string::npos);
@@ -34,11 +39,13 @@ int do_parse(std::string const &s, std::string::size_type &pos) {
ignore = true;
}
pos = e + 1;
} else if (std::isdigit(s[pos]) || s[pos] == '-') {
}
else if (std::isdigit(s[pos]) || s[pos] == '-') {
std::size_t len = 0;
result += std::stoi(s.substr(pos), &len);
pos += len;
} else {
}
else {
assert(s[pos] == ',' || s[pos] == ':');
++pos;
}
@@ -47,14 +54,16 @@ int do_parse(std::string const &s, std::string::size_type &pos) {
return result;
}
int parse_numbers(std::string const &s) {
int parse_numbers(std::string const& s)
{
std::string::size_type pos = 0;
int result = do_parse(s, pos);
assert(pos == s.size());
return result;
}
int main(int argc, char **argv) {
int main(int argc, char** argv)
{
int acc = 0;
for (std::string line; std::getline(std::cin, line);) {
acc += parse_numbers(line);