solanaceae_factorio/src/log_parse.cpp

27 lines
706 B
C++
Raw Normal View History

2024-06-10 21:37:31 +02:00
#include "./log_parse.hpp"
#include <regex>
std::optional<LPLRes> log_parse_line(std::string_view line) {
2024-06-10 21:48:59 +02:00
if (line.empty()) {
return std::nullopt;
}
2024-06-11 10:09:55 +02:00
// TODO: make mod name configurable
2024-06-10 21:37:31 +02:00
static const std::regex mod_match{".*Factorio-Event-Logger+.*\\[([A-Z ]+)\\] (.+)$"};
std::cmatch matches;
2024-06-10 21:48:59 +02:00
if (!std::regex_match(line.data(), line.data() + line.size(), matches, mod_match)) {
2024-06-10 21:37:31 +02:00
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)},
};
}