44 lines
1014 B
C++
44 lines
1014 B
C++
#include "module.h"
|
|
#include <fstream>
|
|
#include <nlohmann/json.hpp>
|
|
#include <regex>
|
|
|
|
Module::Module() {}
|
|
|
|
Module::Module(std::string path) {
|
|
std::ifstream settings_file(path);
|
|
nlohmann::json settings = nlohmann::json::parse(settings_file);
|
|
|
|
this->name = settings["name"];
|
|
this->goods_name_regex = settings["goods_name_regex"];
|
|
this->goods_price_regex = settings["goods_price_regex"];
|
|
this->goods_quantity_regex = settings["goods_quantity_regex"];
|
|
}
|
|
|
|
std::smatch Module::parse_name(std::string str) {
|
|
std::regex r(this->goods_name_regex);
|
|
|
|
std::smatch m;
|
|
regex_search(str, m, r);
|
|
|
|
return m;
|
|
}
|
|
std::smatch Module::parse_price(std::string str) {
|
|
std::regex r(this->goods_price_regex);
|
|
|
|
std::smatch m;
|
|
regex_search(str, m, r);
|
|
|
|
return m;
|
|
}
|
|
std::smatch Module::parse_quantity(std::string str) {
|
|
std::regex r(this->goods_quantity_regex);
|
|
|
|
std::smatch m;
|
|
regex_search(str, m, r);
|
|
|
|
return m;
|
|
}
|
|
|
|
std::string Module::get_name() { return this->name; }
|