From 123b921f2afef69bda85889ff0cda36d84ff9281 Mon Sep 17 00:00:00 2001 From: Petra Baranski Date: Thu, 27 Jul 2023 18:46:25 +0200 Subject: [PATCH] style: make regex strings more readable --- include/maddy/checklistparser.h | 6 +++--- include/maddy/emphasizedparser.h | 2 +- include/maddy/imageparser.h | 2 +- include/maddy/italicparser.h | 2 +- include/maddy/latexblockparser.h | 2 +- include/maddy/linkparser.h | 2 +- include/maddy/orderedlistparser.h | 6 +++--- include/maddy/quoteparser.h | 6 +++--- include/maddy/strikethroughparser.h | 2 +- include/maddy/strongparser.h | 4 ++-- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/maddy/checklistparser.h b/include/maddy/checklistparser.h index bfc487c..dab5ffc 100644 --- a/include/maddy/checklistparser.h +++ b/include/maddy/checklistparser.h @@ -54,7 +54,7 @@ public: static bool IsStartingLine(const std::string& line) { - static std::regex re("^- \\[[x| ]\\] .*"); + static std::regex re(R"(^- \[[x| ]\] .*)"); return std::regex_match(line, re); } @@ -92,11 +92,11 @@ protected: static std::regex lineRegex("^(- )"); line = std::regex_replace(line, lineRegex, ""); - static std::regex emptyBoxRegex("^\\[ \\]"); + static std::regex emptyBoxRegex(R"(^\[ \])"); static std::string emptyBoxReplacement = ""; line = std::regex_replace(line, emptyBoxRegex, emptyBoxReplacement); - static std::regex boxRegex("^\\[x\\]"); + static std::regex boxRegex(R"(^\[x\])"); static std::string boxReplacement = ""; line = std::regex_replace(line, boxRegex, boxReplacement); diff --git a/include/maddy/emphasizedparser.h b/include/maddy/emphasizedparser.h index 6838d83..c1b21ed 100644 --- a/include/maddy/emphasizedparser.h +++ b/include/maddy/emphasizedparser.h @@ -41,7 +41,7 @@ public: void Parse(std::string& line) override { - static std::regex re("(?!.*`.*|.*.*)_(?!.*`.*|.*<\\/code>.*)([^_]*)_(?!.*`.*|.*<\\/code>.*)"); + static std::regex re(R"((?!.*`.*|.*.*)_(?!.*`.*|.*<\/code>.*)([^_]*)_(?!.*`.*|.*<\/code>.*))"); static std::string replacement = "$1"; line = std::regex_replace(line, re, replacement); diff --git a/include/maddy/imageparser.h b/include/maddy/imageparser.h index 3ac77ae..65bca7c 100644 --- a/include/maddy/imageparser.h +++ b/include/maddy/imageparser.h @@ -41,7 +41,7 @@ public: void Parse(std::string& line) override { - static std::regex re("\\!\\[([^\\]]*)\\]\\(([^\\]]*)\\)"); + static std::regex re(R"(\!\[([^\]]*)\]\(([^\]]*)\))"); static std::string replacement = "\"$1\"/"; line = std::regex_replace(line, re, replacement); diff --git a/include/maddy/italicparser.h b/include/maddy/italicparser.h index ed59744..ac3df0f 100644 --- a/include/maddy/italicparser.h +++ b/include/maddy/italicparser.h @@ -39,7 +39,7 @@ public: void Parse(std::string& line) override { - static std::regex re("(?!.*`.*|.*.*)\\*(?!.*`.*|.*<\\/code>.*)([^\\*]*)\\*(?!.*`.*|.*<\\/code>.*)"); + static std::regex re(R"((?!.*`.*|.*.*)\*(?!.*`.*|.*<\/code>.*)([^\*]*)\*(?!.*`.*|.*<\/code>.*))"); static std::string replacement = "$1"; line = std::regex_replace(line, re, replacement); } diff --git a/include/maddy/latexblockparser.h b/include/maddy/latexblockparser.h index 02d66cb..f668523 100644 --- a/include/maddy/latexblockparser.h +++ b/include/maddy/latexblockparser.h @@ -78,7 +78,7 @@ public: static bool IsStartingLine(const std::string& line) { - static std::regex re("^(?:\\$){2}(.*)$"); + static std::regex re(R"(^(?:\$){2}(.*)$)"); return std::regex_match(line, re); } diff --git a/include/maddy/linkparser.h b/include/maddy/linkparser.h index e382f21..e634d43 100644 --- a/include/maddy/linkparser.h +++ b/include/maddy/linkparser.h @@ -41,7 +41,7 @@ public: void Parse(std::string& line) override { - static std::regex re("\\[([^\\]]*)\\]\\(([^\\]]*)\\)"); + static std::regex re(R"(\[([^\]]*)\]\(([^\]]*)\))"); static std::string replacement = "$1"; line = std::regex_replace(line, re, replacement); diff --git a/include/maddy/orderedlistparser.h b/include/maddy/orderedlistparser.h index e41d3b1..27a2aca 100644 --- a/include/maddy/orderedlistparser.h +++ b/include/maddy/orderedlistparser.h @@ -89,9 +89,9 @@ protected: bool isStartOfNewListItem = this->isStartOfNewListItem(line); uint32_t indentation = getIndentationWidth(line); - static std::regex orderedlineRegex("^[1-9]+[0-9]*\\. "); + static std::regex orderedlineRegex(R"(^[1-9]+[0-9]*\. )"); line = std::regex_replace(line, orderedlineRegex, ""); - static std::regex unorderedlineRegex("^\\* "); + static std::regex unorderedlineRegex(R"(^\* )"); line = std::regex_replace(line, unorderedlineRegex, ""); if (!this->isStarted) @@ -132,7 +132,7 @@ private: bool isStartOfNewListItem(const std::string& line) const { - static std::regex re("^(?:[1-9]+[0-9]*\\. |\\* ).*"); + static std::regex re(R"(^(?:[1-9]+[0-9]*\. |\* ).*)"); return std::regex_match(line, re); } }; // class OrderedListParser diff --git a/include/maddy/quoteparser.h b/include/maddy/quoteparser.h index a3b48d0..c0415dd 100644 --- a/include/maddy/quoteparser.h +++ b/include/maddy/quoteparser.h @@ -54,7 +54,7 @@ public: static bool IsStartingLine(const std::string& line) { - static std::regex re("^\\>.*"); + static std::regex re(R"(^\>.*)"); return std::regex_match(line, re); } @@ -144,9 +144,9 @@ protected: void parseBlock(std::string& line) override { - static std::regex lineRegexWithSpace("^\\> "); + static std::regex lineRegexWithSpace(R"(^\> )"); line = std::regex_replace(line, lineRegexWithSpace, ""); - static std::regex lineRegexWithoutSpace("^\\>"); + static std::regex lineRegexWithoutSpace(R"(^\>)"); line = std::regex_replace(line, lineRegexWithoutSpace, ""); if (!line.empty()) diff --git a/include/maddy/strikethroughparser.h b/include/maddy/strikethroughparser.h index 2640459..0c5a8ca 100644 --- a/include/maddy/strikethroughparser.h +++ b/include/maddy/strikethroughparser.h @@ -39,7 +39,7 @@ public: void Parse(std::string& line) override { - static std::regex re("(?!.*`.*|.*.*)\\~\\~(?!.*`.*|.*<\\/code>.*)([^\\~]*)\\~\\~(?!.*`.*|.*<\\/code>.*)"); + static std::regex re(R"((?!.*`.*|.*.*)\~\~(?!.*`.*|.*<\/code>.*)([^\~]*)\~\~(?!.*`.*|.*<\/code>.*))"); static std::string replacement = "$1"; line = std::regex_replace(line, re, replacement); diff --git a/include/maddy/strongparser.h b/include/maddy/strongparser.h index 589dacc..6e5c41c 100644 --- a/include/maddy/strongparser.h +++ b/include/maddy/strongparser.h @@ -43,8 +43,8 @@ public: { static std::vector res { - std::regex{"(?!.*`.*|.*.*)\\*\\*(?!.*`.*|.*<\\/code>.*)([^\\*\\*]*)\\*\\*(?!.*`.*|.*<\\/code>.*)"}, - std::regex{"(?!.*`.*|.*.*)__(?!.*`.*|.*<\\/code>.*)([^__]*)__(?!.*`.*|.*<\\/code>.*)"} + std::regex{R"((?!.*`.*|.*.*)\*\*(?!.*`.*|.*<\/code>.*)([^\*\*]*)\*\*(?!.*`.*|.*<\/code>.*))"}, + std::regex{R"((?!.*`.*|.*.*)__(?!.*`.*|.*<\/code>.*)([^__]*)__(?!.*`.*|.*<\/code>.*))"} }; static std::string replacement = "$1"; for (const auto& re : res)