complete parsing
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
#include "module.h"
|
||||
#include "../settings.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
|
||||
std::string to_utf8(std::wstring wide_string) {
|
||||
static std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_conv;
|
||||
return utf8_conv.to_bytes(wide_string);
|
||||
}
|
||||
|
||||
std::wstring from_utf8(std::string string) {
|
||||
static std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_conv;
|
||||
return utf8_conv.from_bytes(string);
|
||||
}
|
||||
|
||||
Module::Module() {}
|
||||
|
||||
@@ -9,35 +24,46 @@ 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"];
|
||||
this->name = from_utf8(settings["name"]);
|
||||
this->goods_name_regex = from_utf8(settings["goods_name_regex"]);
|
||||
this->goods_price_regex = from_utf8(settings["goods_price_regex"]);
|
||||
this->goods_quantity_regex = from_utf8(settings["goods_quantity_regex"]);
|
||||
#ifdef DEBUG
|
||||
std::wcout << "Name: " << this->name << std::endl;
|
||||
std::wcout << "Goods name regex: " << this->goods_name_regex << std::endl;
|
||||
std::wcout << "Goods price regex: " << this->goods_price_regex << std::endl;
|
||||
std::wcout << "Goods quantity regex: " << this->goods_quantity_regex << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::smatch Module::parse_name(std::string str) {
|
||||
std::regex r(this->goods_name_regex);
|
||||
std::vector<std::string> Module::parse_name(std::wstring str) {
|
||||
std::vector<std::string> result;
|
||||
std::wregex r(this->goods_name_regex, std::regex::collate);
|
||||
|
||||
std::smatch m;
|
||||
regex_search(str, m, r);
|
||||
for (std::wsregex_iterator it {str.begin(), str.end(), r}, end {}; it != end; it ++) {
|
||||
result.push_back(to_utf8(it->str()));
|
||||
}
|
||||
|
||||
return m;
|
||||
return result;
|
||||
}
|
||||
std::smatch Module::parse_price(std::string str) {
|
||||
std::regex r(this->goods_price_regex);
|
||||
std::vector<std::string> Module::parse_price(std::wstring str) {
|
||||
std::vector<std::string> result;
|
||||
std::wregex r(this->goods_price_regex, std::regex::collate);
|
||||
|
||||
std::smatch m;
|
||||
regex_search(str, m, r);
|
||||
for (std::wsregex_iterator it {str.begin(), str.end(), r}, end {}; it != end; it ++) {
|
||||
result.push_back(to_utf8(it->str()));
|
||||
}
|
||||
|
||||
return m;
|
||||
return result;
|
||||
}
|
||||
std::smatch Module::parse_quantity(std::string str) {
|
||||
std::regex r(this->goods_quantity_regex);
|
||||
std::vector<std::string> Module::parse_quantity(std::wstring str) {
|
||||
std::vector<std::string> result;
|
||||
std::wregex r(this->goods_quantity_regex, std::regex::collate);
|
||||
|
||||
std::smatch m;
|
||||
regex_search(str, m, r);
|
||||
|
||||
return m;
|
||||
for (std::wsregex_iterator it {str.begin(), str.end(), r}, end {}; it != end; it ++) {
|
||||
result.push_back(to_utf8(it->str()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Module::get_name() { return this->name; }
|
||||
std::wstring Module::get_name() { return this->name; }
|
||||
|
||||
Reference in New Issue
Block a user