simple regex and test
This commit is contained in:
@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)
|
||||
project(solanaceae)
|
||||
|
||||
add_library(solanaceae_factorio
|
||||
./log_parse.hpp
|
||||
./log_parse.cpp
|
||||
./factorio.hpp
|
||||
./factorio.cpp
|
||||
)
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <solanaceae/message3/components.hpp>
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
|
||||
#include "./log_parse.hpp"
|
||||
|
||||
Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm) : _cr(cr), _rmm(rmm) {
|
||||
_rmm.subscribe(this, RegistryMessageModel_Event::message_construct);
|
||||
}
|
||||
|
@ -12,6 +12,5 @@ class Factorio : public RegistryMessageModelEventI {
|
||||
|
||||
protected: // rmm
|
||||
bool onEvent(const Message::Events::MessageConstruct& e) override;
|
||||
|
||||
};
|
||||
|
||||
|
21
src/log_parse.cpp
Normal file
21
src/log_parse.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "./log_parse.hpp"
|
||||
|
||||
#include <regex>
|
||||
|
||||
std::optional<LPLRes> log_parse_line(std::string_view line) {
|
||||
static const std::regex mod_match{".*Factorio-Event-Logger+.*\\[([A-Z ]+)\\] (.+)$"};
|
||||
|
||||
std::cmatch matches;
|
||||
if (!std::regex_match(line.cbegin(), line.cend(), 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)},
|
||||
};
|
||||
}
|
11
src/log_parse.hpp
Normal file
11
src/log_parse.hpp
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
|
||||
struct LPLRes {
|
||||
std::string_view event;
|
||||
std::string_view info;
|
||||
};
|
||||
|
||||
std::optional<LPLRes> log_parse_line(std::string_view line);
|
Reference in New Issue
Block a user