migrate to boost::regex
This commit is contained in:
parent
1fa69c3a69
commit
d83f106a91
|
@ -51,6 +51,7 @@ if (BUILD_OFD_BINARYEYE_SCAN)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
SET(CMAKE_BUILD_TYPE Debug)
|
SET(CMAKE_BUILD_TYPE Debug)
|
||||||
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||||
|
|
||||||
set(CMAKE_AUTOUIC ON)
|
set(CMAKE_AUTOUIC ON)
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
@ -215,6 +216,16 @@ endif()
|
||||||
|
|
||||||
target_link_libraries(checks-parser PRIVATE -lcurl)
|
target_link_libraries(checks-parser PRIVATE -lcurl)
|
||||||
|
|
||||||
|
find_package(Boost 1.45.0 COMPONENTS boost_regex)
|
||||||
|
|
||||||
|
if(Boost_FOUND)
|
||||||
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(checks-parser PUBLIC ${Boost_LIBRARIES})
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "No BOOST library found. Please, install one. If you beleive this is an error, please, contact the developer.")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
if (BUILD_OCR_MODE OR BUILD_OFD_LOCAL_QR_SCAN OR BUILD_OFD_BINARYEYE_SCAN)
|
if (BUILD_OCR_MODE OR BUILD_OFD_LOCAL_QR_SCAN OR BUILD_OFD_BINARYEYE_SCAN)
|
||||||
find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs)
|
find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs)
|
||||||
target_link_libraries(checks-parser PRIVATE ${OpenCV_LIBS})
|
target_link_libraries(checks-parser PRIVATE ${OpenCV_LIBS})
|
||||||
|
|
|
@ -13,19 +13,20 @@ RUN DEBIAN_FRONTEND=noninteractive apt install -y libmpc-dev libmpfr-dev libgmp-
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|
||||||
RUN wget https://mirror.linux-ia64.org/gnu/gcc/releases/gcc-12.3.0/gcc-12.3.0.tar.gz
|
#RUN wget https://mirror.linux-ia64.org/gnu/gcc/releases/gcc-12.3.0/gcc-12.3.0.tar.gz
|
||||||
RUN tar xf gcc-12.3.0.tar.gz
|
RUN wget https://mirror.linux-ia64.org/gnu/gcc/releases/gcc-13.3.0/gcc-13.3.0.tar.gz
|
||||||
|
RUN tar xf gcc-13.3.0.tar.gz
|
||||||
|
|
||||||
RUN rm gcc-12.3.0.tar.gz
|
RUN rm gcc-13.3.0.tar.gz
|
||||||
|
|
||||||
WORKDIR /gcc-12.3.0
|
WORKDIR /gcc-13.3.0
|
||||||
RUN ./configure --disable-multilib --prefix=/usr
|
RUN ./configure --disable-multilib --prefix=/usr
|
||||||
RUN make -j $(nproc) && make install
|
RUN make -j $(nproc) && make install
|
||||||
|
|
||||||
RUN cp /lib64/* /lib/x86_64-linux-gnu || :
|
RUN cp /lib64/* /lib/x86_64-linux-gnu || :
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
RUN rm -rf gcc-12.3.0
|
RUN rm -rf gcc-13.3.0
|
||||||
|
|
||||||
# Download linuxdeployqt
|
# Download linuxdeployqt
|
||||||
RUN wget https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage -O /usr/bin/linuxdeployqt && \
|
RUN wget https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage -O /usr/bin/linuxdeployqt && \
|
||||||
|
@ -65,13 +66,13 @@ RUN cmake -DBUILD_TRANSLATIONS=on .. && make -j 8
|
||||||
|
|
||||||
WORKDIR /appimage/AppDir/usr/bin
|
WORKDIR /appimage/AppDir/usr/bin
|
||||||
|
|
||||||
RUN cp /appimage/build/checks-parser
|
RUN cp /appimage/build/checks-parser .
|
||||||
|
|
||||||
WORKDIR /appimage
|
WORKDIR /appimage
|
||||||
|
|
||||||
RUN linuxdeployqt --appimage-extract-and-run AppDir/usr/bin/checks-parser -no-copy-copyright-files -appimage
|
RUN linuxdeployqt --appimage-extract-and-run AppDir/usr/bin/checks-parser -no-copy-copyright-files -appimage || :
|
||||||
|
|
||||||
RUN mkdir -p /output
|
RUN mkdir -p /output || :
|
||||||
RUN cp Checks_parser-x86_64.AppImage /output
|
RUN cp Checks_parser-x86_64.AppImage /output || :
|
||||||
|
|
||||||
ENTRYPOINT bash
|
ENTRYPOINT bash
|
||||||
|
|
6
main.cpp
6
main.cpp
|
@ -50,12 +50,10 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
QTranslator translator;
|
QTranslator translator;
|
||||||
QString lang = "en_US";
|
QString lang = "en_US";
|
||||||
|
|
||||||
bool languageSettingPresent = false;
|
bool languageSettingPresent = false;
|
||||||
#if NLOHMANN_JSON_VERSION_MAJOR < 3 && NLOHMANN_JSON_VERSION_MINOR < 6 && NLOHMANN_JSON_VERSION_PATCH < 0
|
|
||||||
languageSettingPresent = s.get_all_settings().find("language") != s.get_all_settings().end();
|
languageSettingPresent = s.get_all_settings().find("language") != s.get_all_settings().end();
|
||||||
#else
|
|
||||||
languageSettingPresent = s.get_all_settings().contains("language");
|
|
||||||
#endif
|
|
||||||
if (languageSettingPresent) {
|
if (languageSettingPresent) {
|
||||||
lang = QString::fromStdString(s.get_all_settings()["language"]);
|
lang = QString::fromStdString(s.get_all_settings()["language"]);
|
||||||
} else if (translator.load(":/translation/"+QLocale::system().name()+".qm")) {
|
} else if (translator.load(":/translation/"+QLocale::system().name()+".qm")) {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
struct data {};
|
struct data {};
|
||||||
|
|
||||||
|
@ -23,11 +24,11 @@ void write_modules(void *buffer, size_t size, size_t nmemb, void *modules) {
|
||||||
(std::vector<std::string> *)modules;
|
(std::vector<std::string> *)modules;
|
||||||
std::string to_parse = std::string((char*)buffer);
|
std::string to_parse = std::string((char*)buffer);
|
||||||
|
|
||||||
std::regex r("(?!\\\")\\w+\\.json(?!\\\")", std::regex::collate);
|
boost::regex r("(?!\\\")\\w+\\.json(?!\\\")", boost::regex::collate);
|
||||||
std::smatch res;
|
boost::smatch res;
|
||||||
|
|
||||||
std::string::const_iterator search(to_parse.cbegin());
|
std::string::const_iterator search(to_parse.cbegin());
|
||||||
while (std::regex_search(search, to_parse.cend(), res, r)) {
|
while (boost::regex_search(search, to_parse.cend(), res, r)) {
|
||||||
modules_vector->push_back(res[0]);
|
modules_vector->push_back(res[0]);
|
||||||
search = res.suffix().first;
|
search = res.suffix().first;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <regex>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "../utils/utils.h"
|
#include "../utils/utils.h"
|
||||||
|
#include <boost/regex.hpp>
|
||||||
StoreModule::StoreModule() {}
|
StoreModule::StoreModule() {}
|
||||||
|
|
||||||
StoreModule::StoreModule(std::string path) {
|
StoreModule::StoreModule(std::string path) {
|
||||||
|
@ -31,9 +30,9 @@ StoreModule::StoreModule(std::string path) {
|
||||||
|
|
||||||
std::vector<std::string> StoreModule::parse_name(std::wstring str) {
|
std::vector<std::string> StoreModule::parse_name(std::wstring str) {
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
std::wregex r(this->goods_name_regex, std::regex_constants::multiline);
|
boost::wregex r(this->goods_name_regex, boost::regex_constants::extended);
|
||||||
|
|
||||||
for (std::wsregex_iterator it{str.begin(), str.end(), r}, end{}; it != end;
|
for (boost::wsregex_iterator it{str.begin(), str.end(), r}, end{}; it != end;
|
||||||
it++) {
|
it++) {
|
||||||
result.push_back(to_utf8(it->str()));
|
result.push_back(to_utf8(it->str()));
|
||||||
}
|
}
|
||||||
|
@ -43,9 +42,9 @@ std::vector<std::string> StoreModule::parse_name(std::wstring str) {
|
||||||
|
|
||||||
std::vector<std::string> StoreModule::parse_price(std::wstring str) {
|
std::vector<std::string> StoreModule::parse_price(std::wstring str) {
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
std::wregex r(this->goods_price_regex, std::regex::collate);
|
boost::wregex r(this->goods_price_regex, boost::regex::collate);
|
||||||
|
|
||||||
for (std::wsregex_iterator it{str.begin(), str.end(), r}, end{}; it != end;
|
for (boost::wsregex_iterator it{str.begin(), str.end(), r}, end{}; it != end;
|
||||||
it++) {
|
it++) {
|
||||||
result.push_back(to_utf8(it->str()));
|
result.push_back(to_utf8(it->str()));
|
||||||
}
|
}
|
||||||
|
@ -55,9 +54,9 @@ std::vector<std::string> StoreModule::parse_price(std::wstring str) {
|
||||||
|
|
||||||
std::vector<std::string> StoreModule::parse_quantity(std::wstring str) {
|
std::vector<std::string> StoreModule::parse_quantity(std::wstring str) {
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
std::wregex r(this->goods_quantity_regex, std::regex::collate);
|
boost::wregex r(this->goods_quantity_regex, boost::regex::collate);
|
||||||
|
|
||||||
for (std::wsregex_iterator it{str.begin(), str.end(), r}, end{}; it != end;
|
for (boost::wsregex_iterator it{str.begin(), str.end(), r}, end{}; it != end;
|
||||||
it++) {
|
it++) {
|
||||||
result.push_back(to_utf8(it->str()));
|
result.push_back(to_utf8(it->str()));
|
||||||
}
|
}
|
||||||
|
@ -68,10 +67,10 @@ std::wstring StoreModule::trim_check(std::wstring& check) {
|
||||||
unsigned int start_pos;
|
unsigned int start_pos;
|
||||||
unsigned int end_pos;
|
unsigned int end_pos;
|
||||||
|
|
||||||
std::wregex start_regex(this->check_start_regex, std::regex::collate);
|
boost::wregex start_regex(this->check_start_regex, boost::regex::collate);
|
||||||
std::wregex end_regex(this->check_end_regex, std::regex::collate);
|
boost::wregex end_regex(this->check_end_regex, boost::regex::collate);
|
||||||
|
|
||||||
for (std::wsregex_iterator it{check.begin(), check.end(), start_regex}, end{};
|
for (boost::wsregex_iterator it{check.begin(), check.end(), start_regex}, end{};
|
||||||
it != end; it++) {
|
it != end; it++) {
|
||||||
start_pos = it->position() + it->str().size();
|
start_pos = it->position() + it->str().size();
|
||||||
break;
|
break;
|
||||||
|
@ -79,7 +78,7 @@ std::wstring StoreModule::trim_check(std::wstring& check) {
|
||||||
|
|
||||||
check = check.substr(start_pos, check.size());
|
check = check.substr(start_pos, check.size());
|
||||||
|
|
||||||
for (std::wsregex_iterator it{check.begin(), check.end(), end_regex}, end{};
|
for (boost::wsregex_iterator it{check.begin(), check.end(), end_regex}, end{};
|
||||||
it != end; it++) {
|
it != end; it++) {
|
||||||
end_pos = it->position() - 1;
|
end_pos = it->position() - 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
#endif
|
#endif
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "settings/settings.h"
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
|
|
||||||
#ifdef BUILD_OFD_BINARYEYE_SCAN
|
#ifdef BUILD_OFD_BINARYEYE_SCAN
|
||||||
|
@ -97,10 +97,10 @@ std::wstring substring_from_to(std::wstring& text, std::wstring from, std::wstri
|
||||||
|
|
||||||
std::wstring substring;
|
std::wstring substring;
|
||||||
|
|
||||||
std::wregex start_regex(from);
|
boost::wregex start_regex(from);
|
||||||
std::wregex end_regex(to);
|
boost::wregex end_regex(to);
|
||||||
|
|
||||||
for (std::wsregex_iterator it{text.begin(), text.end(), start_regex}, end{};
|
for (boost::wsregex_iterator it{text.begin(), text.end(), start_regex}, end{};
|
||||||
it != end; it++) {
|
it != end; it++) {
|
||||||
start_pos = it->position() + it->str().size();
|
start_pos = it->position() + it->str().size();
|
||||||
break;
|
break;
|
||||||
|
@ -109,7 +109,7 @@ std::wstring substring_from_to(std::wstring& text, std::wstring from, std::wstri
|
||||||
if(text == from_utf8("")) return text;
|
if(text == from_utf8("")) return text;
|
||||||
substring = text.substr(start_pos, text.size());
|
substring = text.substr(start_pos, text.size());
|
||||||
|
|
||||||
for (std::wsregex_iterator it{substring.begin(), substring.end(), end_regex}, end{};
|
for (boost::wsregex_iterator it{substring.begin(), substring.end(), end_regex}, end{};
|
||||||
it != end; it++) {
|
it != end; it++) {
|
||||||
end_pos = it->position();
|
end_pos = it->position();
|
||||||
break;
|
break;
|
||||||
|
@ -131,10 +131,10 @@ std::wstring trim_html_response(std::wstring& check) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::wstring> find_in_html(std::string& html, std::string regex, std::string html_start, std::string html_end) {
|
std::vector<std::wstring> find_in_html(std::string& html, std::string regex, std::string html_start, std::string html_end) {
|
||||||
std::regex searching_regex(regex);
|
boost::regex searching_regex(regex);
|
||||||
|
|
||||||
std::vector<std::wstring> parsed;
|
std::vector<std::wstring> parsed;
|
||||||
for (std::sregex_iterator it{html.begin(), html.end(), searching_regex}, end{};
|
for (boost::sregex_iterator it{html.begin(), html.end(), searching_regex}, end{};
|
||||||
it != end; it++) {
|
it != end; it++) {
|
||||||
|
|
||||||
std::wstring found_entry = from_utf8(it->str());
|
std::wstring found_entry = from_utf8(it->str());
|
||||||
|
|
Loading…
Reference in New Issue