diff --git a/modules/pyaterochka.json b/modules/pyaterochka.json index f25b8e8..62b6b23 100644 --- a/modules/pyaterochka.json +++ b/modules/pyaterochka.json @@ -1,7 +1,8 @@ { "name":"Пятёрочка", - "goods_name_regex": "([\\(\\)\\%\\*a-zA-Z0-9\u0401\u0451\u0410-\u044f \\.\\-\/]{17,100})", + "goods_name_regex": "^\\d+\\s\\t[\\(\\)\\%\\*a-zA-Z0-9\\u0401\\u0451\\u0410-\\u044f \\.\\-\\/]+", "goods_price_regex": "[0-9]{0,4}[^%]\\.[0-9]{2} ", + "goods_net_weight_regex": "((\\d+(\\.|,)?\\d{0,}((м|)л|(к|м|)г|т|ц|шт|(pc|)s|(m|k|)g|(m|)l|t))(\\s|\\t){0,})+", "goods_quantity_regex": "([0-9]{0,4}[^%]\\.[0-9]{3} )|(\t\\d )", "check_start_regex": "КАССОВЫЙ ЧЕК\nприход", "check_end_regex": "Итог\\:.{0,3}[0-9]{0,6}\\.[0-9]{2}" diff --git a/parser/module.cpp b/parser/module.cpp index 8677f5c..614934d 100644 --- a/parser/module.cpp +++ b/parser/module.cpp @@ -6,14 +6,17 @@ #include #include +#include + StoreModule::StoreModule() {} std::vector StoreModule::parse(std::wstring str, std::wstring regexp, boost::regex_constants::flag_type_ flag) { std::vector result; boost::wregex r(regexp, flag); - + std::cout << "Handling: " << to_utf8(str) << std::endl; for (boost::wsregex_iterator it{str.begin(), str.end(), r}, end{}; it != end; it++) { + std::wcout << "Parsed" << it->str() << std::endl; result.push_back(to_utf8(it->str())); } @@ -34,7 +37,7 @@ StoreModule::StoreModule(std::string path) { } std::vector StoreModule::parse_name(std::wstring str) { - return parse(str, this->goods_name_regex, boost::regex_constants::extended); + return parse(str, this->goods_name_regex, boost::regex_constants::perl); } std::vector StoreModule::parse_price(std::wstring str) { @@ -49,6 +52,7 @@ std::vector StoreModule::parse_net_weight(std::vector result.push_back("?"); } else { result.push_back(parsed[0]); + name.erase(0, name.find(parsed[0]) + parsed[0].length()); } } return result; diff --git a/parser/parser.cpp b/parser/parser.cpp index bd44543..d72e5ee 100644 --- a/parser/parser.cpp +++ b/parser/parser.cpp @@ -68,7 +68,7 @@ std::vector Parser::parse(std::wstring check_plaintext) { std::vector goods_quantities = module.parse_quantity(check_plaintext); - if (areAllSizesEqual(goods_names, goods_prices, goods_net_weights, goods_quantities)) { + if (!areAllSizesEqual(goods_names, goods_prices, goods_net_weights, goods_quantities)) { // dumpVectorsToStderr(goods_names, goods_prices, goods_net_weights, goods_quantities); diff --git a/settingsdialog.cpp b/settingsdialog.cpp index 9b92f07..50c7cb0 100644 --- a/settingsdialog.cpp +++ b/settingsdialog.cpp @@ -42,15 +42,16 @@ SettingsDialog::SettingsDialog(QWidget *parent) int currentLanguageIndex = 0; bool languageSettingPresent = false; - //TODO: check that "language" exists before getting its value languageSettingPresent = settings.get_all_settings().find("language") != settings.get_all_settings().end(); + if (languageSettingPresent) { + currentLanguageIndex = ui->languageComboBox->findText(QString::fromStdString(this->settings.get_all_settings()["language"])); + + } else { currentLanguageIndex = ui->languageComboBox->findText(QLocale::system().name()); if (currentLanguageIndex < 0) { currentLanguageIndex = ui->languageComboBox->findText("en_US"); } - } else { - currentLanguageIndex = ui->languageComboBox->findText(QString::fromStdString(this->settings.get_all_settings()["language"])); } ui->languageComboBox->setCurrentIndex(currentLanguageIndex); diff --git a/translations/en_US.ts b/translations/en_US.ts index 5fd5505..0b13763 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -562,12 +562,12 @@ SettingsDialog - + You need to restart program to apply language changes You need to restart program to apply language changes - + Restart required Restart required diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts index 819e47c..41f1122 100644 --- a/translations/ru_RU.ts +++ b/translations/ru_RU.ts @@ -562,12 +562,12 @@ SettingsDialog - + You need to restart program to apply language changes Требуется перезагрузить программу, чтобы применить изменения языка - + Restart required Требуется перезагрузка diff --git a/utils/utils.cpp b/utils/utils.cpp index f40ce3b..c03f20a 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -98,6 +98,20 @@ std::vector split(std::string s, std::string delimiter) { return result; } +std::vector split(std::wstring s, std::wstring delimiter) { + std::vector result; + size_t pos = 0; + std::wstring token; + while ((pos = s.find(delimiter)) != std::string::npos) { + token = s.substr(0, pos); + result.push_back(token); + s.erase(0, pos + delimiter.length()); + } + result.push_back(s); + + return result; +} + std::wstring substring_from_to(std::wstring& text, std::wstring from, std::wstring to) { unsigned int start_pos = 0; unsigned int end_pos = 0; @@ -169,12 +183,13 @@ std::vector find_amounts_in_html(std::string html) { std::vector find_net_weights_in_names(std::vector &names) { std::vector result; for (std::wstring &name : names ) { - boost::wregex regexp(from_utf8("((\\d+(.|,)?\\d?((м|)л|(к|м|)г|т|ц|шт|(pc|)s|(m|k|)g|(m|)l|t)).?)+"), boost::regex_constants::collate); + boost::wregex regexp(from_utf8("((\\d+(\\.|,)?\\d{0,}((м|)л|(к|м|)г|т|ц|шт|(pc|)s|(m|k|)g|(m|)l|t))(\\s|\\t){0,})+"), boost::regex_constants::collate); bool found = false; for (boost::wsregex_iterator it{name.begin(), name.end(), regexp}, end{}; it != end; it++) { result.push_back(it->str()); found = true; + name.erase(it->position(), it->str().length()); break; } if (!found) { diff --git a/utils/utils.h b/utils/utils.h index 3cba741..7946b2a 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -17,6 +17,7 @@ bool areAllSizesEqual(const std::vector& v1, const std::vector& v2, const std::vector& v3, const std::vector& v4); std::vector split(std::string, std::string); +std::vector split(std::wstring s, std::wstring delimiter); #ifdef BUILD_OFD_MODE Check parseOfdRuAnswer(std::string);