From 22f39eb8d82c5c1b956c93dcff12a5533f1a425b Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 11 Nov 2018 21:28:45 +0100 Subject: [PATCH] Temporarily switch to boost::regex In combination with musl, parser crashed. glibc fine. Could not pinpoint down the exact reason mainly due to time constraints. Strange, in both cases actually libstdc++ is used, so this is very odd. --- Makefile | 4 ++-- parser.cpp | 7 +++---- parser.h | 4 ++-- utils.cpp | 12 +++++++----- utils.h | 3 ++- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index af3545c..cf519d1 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -CXXFLAGS=-std=c++17 -O0 -g -pg -no-pie -pipe -MMD -Wall -Wextra +CXXFLAGS=-std=c++17 -O0 -g -no-pie -pipe -MMD -Wall -Wextra RELEASE_CXXFLAGS=-std=c++17 -O3 -pipe -MMD -Wall -Wextra -LDFLAGS=-lsqlite3 -lpthread -lcrypto -lstdc++fs +LDFLAGS=-lsqlite3 -lpthread -lcrypto -lboost_regex -lstdc++fs #currently default g++ versions in most distros do not usually support c++17 well enough CXX=g++-8.2.0 diff --git a/parser.cpp b/parser.cpp index c5adb20..c87d437 100644 --- a/parser.cpp +++ b/parser.cpp @@ -27,7 +27,6 @@ SOFTWARE. #include "parser.h" #include "utils.h" #include "htmllink.h" - std::vector Parser::extractHeadlines(std::string content) const { std::vector result; @@ -83,7 +82,7 @@ std::string Parser::extractCommand(std::string cmdname, std::string content) con } return ""; } -std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const +std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider, boost::smatch &match) const { std::string linktag = match.str(1); std::string inside = match.str(2); @@ -124,8 +123,8 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, std::st { std::string result; //we don't care about commands, but we nevertheless replace them with empty strings - std::regex tagfinder(R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:rename|cmd:redirect)*?\]((\s|\S)*?)\[/\1])"); - result = utils::regex_callback_replacer(tagfinder, content, [&](std::smatch &match) + boost::regex tagfinder(R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:rename|cmd:redirect)*?\]((\s|\S)*?)\[/\1])"); + result = utils::regex_callback_replacer(tagfinder, content, [&](boost::smatch &match) { std::string tag = match.str(1); std::string content = match.str(2); diff --git a/parser.h b/parser.h index 1973180..0296556 100644 --- a/parser.h +++ b/parser.h @@ -1,13 +1,13 @@ #ifndef PARSER_H #define PARSER_H -#include +#include #include "iparser.h" class Parser : public IParser { private: - std::string processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const; + std::string processLink(const PageDao &pageDao, UrlProvider &urlProvider, boost::smatch &match) const; public: std::string extractCommand(std::string cmdname, std::string content) const ; std::vector extractHeadlines(std::string content) const override ; diff --git a/utils.cpp b/utils.cpp index 01ccde0..ca5d09d 100644 --- a/utils.cpp +++ b/utils.cpp @@ -24,8 +24,10 @@ SOFTWARE. #include #include #include +#include #include "logger.h" #include "utils.h" + //TODO: instead of returning vector maybe provide an iterator version too. //TODO: % may not be necessary (was in C version just to be sure against format string attacks @@ -138,14 +140,14 @@ std::string utils::readCompleteFile(std::string_view filepath) return content; } -std::string utils::regex_callback_replacer(std::regex regex, const std::string &input, std::function callback) +std::string utils::regex_callback_replacer(boost::regex regex, const std::string &input, std::function callback) { std::string result; - auto tagsbegin = std::sregex_iterator(input.begin(), input.end(), regex); - auto tagsend = std::sregex_iterator(); + auto tagsbegin = boost::sregex_iterator(input.begin(), input.end(), regex); + auto tagsend = boost::sregex_iterator(); auto matchbegin = 0; - for (std::sregex_iterator i = tagsbegin; i != tagsend; ++i) { - std::smatch match = *i; + for (boost::sregex_iterator i = tagsbegin; i != tagsend; ++i) { + boost::smatch match = *i; auto matchlength = match.length(0); auto matchpos = match.position(); diff --git a/utils.h b/utils.h index f159171..a56686e 100644 --- a/utils.h +++ b/utils.h @@ -8,6 +8,7 @@ #include #include #include +#include namespace utils { @@ -61,7 +62,7 @@ namespace utils return result; } - std::string regex_callback_replacer(std::regex regex, const std::string &input, std::function callback ); + std::string regex_callback_replacer(boost::regex regex, const std::string &input, std::function callback); std::string readCompleteFile(std::string_view filepath);