solanaceae_factorio/src/log_parse.cpp
Green Sky 70317ab4db
Some checks are pending
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
ContinuousIntegration / linux (push) Successful in 22s
more event boilerplate
2024-06-11 10:09:55 +02:00

27 lines
706 B
C++

#include "./log_parse.hpp"
#include <regex>
std::optional<LPLRes> log_parse_line(std::string_view line) {
if (line.empty()) {
return std::nullopt;
}
// TODO: make mod name configurable
static const std::regex mod_match{".*Factorio-Event-Logger+.*\\[([A-Z ]+)\\] (.+)$"};
std::cmatch matches;
if (!std::regex_match(line.data(), line.data() + line.size(), matches, mod_match)) {
return std::nullopt;
}
if (matches.empty() || matches.size() != 3) {
return std::nullopt;
}
return LPLRes{
std::string_view{matches[1].first, static_cast<size_t>(matches[1].second - matches[1].first)},
std::string_view{matches[2].first, static_cast<size_t>(matches[2].second - matches[2].first)},
};
}