style: make regex strings more readable

This commit is contained in:
Petra Baranski
2023-07-27 18:46:25 +02:00
parent aecb1b30e6
commit 123b921f2a
10 changed files with 17 additions and 17 deletions

View File

@@ -54,7 +54,7 @@ public:
static bool static bool
IsStartingLine(const std::string& line) IsStartingLine(const std::string& line)
{ {
static std::regex re("^- \\[[x| ]\\] .*"); static std::regex re(R"(^- \[[x| ]\] .*)");
return std::regex_match(line, re); return std::regex_match(line, re);
} }
@@ -92,11 +92,11 @@ protected:
static std::regex lineRegex("^(- )"); static std::regex lineRegex("^(- )");
line = std::regex_replace(line, lineRegex, ""); line = std::regex_replace(line, lineRegex, "");
static std::regex emptyBoxRegex("^\\[ \\]"); static std::regex emptyBoxRegex(R"(^\[ \])");
static std::string emptyBoxReplacement = "<input type=\"checkbox\"/>"; static std::string emptyBoxReplacement = "<input type=\"checkbox\"/>";
line = std::regex_replace(line, emptyBoxRegex, emptyBoxReplacement); line = std::regex_replace(line, emptyBoxRegex, emptyBoxReplacement);
static std::regex boxRegex("^\\[x\\]"); static std::regex boxRegex(R"(^\[x\])");
static std::string boxReplacement = "<input type=\"checkbox\" checked=\"checked\"/>"; static std::string boxReplacement = "<input type=\"checkbox\" checked=\"checked\"/>";
line = std::regex_replace(line, boxRegex, boxReplacement); line = std::regex_replace(line, boxRegex, boxReplacement);

View File

@@ -41,7 +41,7 @@ public:
void void
Parse(std::string& line) override Parse(std::string& line) override
{ {
static std::regex re("(?!.*`.*|.*<code>.*)_(?!.*`.*|.*<\\/code>.*)([^_]*)_(?!.*`.*|.*<\\/code>.*)"); static std::regex re(R"((?!.*`.*|.*<code>.*)_(?!.*`.*|.*<\/code>.*)([^_]*)_(?!.*`.*|.*<\/code>.*))");
static std::string replacement = "<em>$1</em>"; static std::string replacement = "<em>$1</em>";
line = std::regex_replace(line, re, replacement); line = std::regex_replace(line, re, replacement);

View File

@@ -41,7 +41,7 @@ public:
void void
Parse(std::string& line) override Parse(std::string& line) override
{ {
static std::regex re("\\!\\[([^\\]]*)\\]\\(([^\\]]*)\\)"); static std::regex re(R"(\!\[([^\]]*)\]\(([^\]]*)\))");
static std::string replacement = "<img src=\"$2\" alt=\"$1\"/>"; static std::string replacement = "<img src=\"$2\" alt=\"$1\"/>";
line = std::regex_replace(line, re, replacement); line = std::regex_replace(line, re, replacement);

View File

@@ -39,7 +39,7 @@ public:
void void
Parse(std::string& line) override Parse(std::string& line) override
{ {
static std::regex re("(?!.*`.*|.*<code>.*)\\*(?!.*`.*|.*<\\/code>.*)([^\\*]*)\\*(?!.*`.*|.*<\\/code>.*)"); static std::regex re(R"((?!.*`.*|.*<code>.*)\*(?!.*`.*|.*<\/code>.*)([^\*]*)\*(?!.*`.*|.*<\/code>.*))");
static std::string replacement = "<i>$1</i>"; static std::string replacement = "<i>$1</i>";
line = std::regex_replace(line, re, replacement); line = std::regex_replace(line, re, replacement);
} }

View File

@@ -78,7 +78,7 @@ public:
static bool static bool
IsStartingLine(const std::string& line) IsStartingLine(const std::string& line)
{ {
static std::regex re("^(?:\\$){2}(.*)$"); static std::regex re(R"(^(?:\$){2}(.*)$)");
return std::regex_match(line, re); return std::regex_match(line, re);
} }

View File

@@ -41,7 +41,7 @@ public:
void void
Parse(std::string& line) override Parse(std::string& line) override
{ {
static std::regex re("\\[([^\\]]*)\\]\\(([^\\]]*)\\)"); static std::regex re(R"(\[([^\]]*)\]\(([^\]]*)\))");
static std::string replacement = "<a href=\"$2\">$1</a>"; static std::string replacement = "<a href=\"$2\">$1</a>";
line = std::regex_replace(line, re, replacement); line = std::regex_replace(line, re, replacement);

View File

@@ -89,9 +89,9 @@ protected:
bool isStartOfNewListItem = this->isStartOfNewListItem(line); bool isStartOfNewListItem = this->isStartOfNewListItem(line);
uint32_t indentation = getIndentationWidth(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, ""); line = std::regex_replace(line, orderedlineRegex, "");
static std::regex unorderedlineRegex("^\\* "); static std::regex unorderedlineRegex(R"(^\* )");
line = std::regex_replace(line, unorderedlineRegex, ""); line = std::regex_replace(line, unorderedlineRegex, "");
if (!this->isStarted) if (!this->isStarted)
@@ -132,7 +132,7 @@ private:
bool bool
isStartOfNewListItem(const std::string& line) const 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); return std::regex_match(line, re);
} }
}; // class OrderedListParser }; // class OrderedListParser

View File

@@ -54,7 +54,7 @@ public:
static bool static bool
IsStartingLine(const std::string& line) IsStartingLine(const std::string& line)
{ {
static std::regex re("^\\>.*"); static std::regex re(R"(^\>.*)");
return std::regex_match(line, re); return std::regex_match(line, re);
} }
@@ -144,9 +144,9 @@ protected:
void void
parseBlock(std::string& line) override parseBlock(std::string& line) override
{ {
static std::regex lineRegexWithSpace("^\\> "); static std::regex lineRegexWithSpace(R"(^\> )");
line = std::regex_replace(line, lineRegexWithSpace, ""); line = std::regex_replace(line, lineRegexWithSpace, "");
static std::regex lineRegexWithoutSpace("^\\>"); static std::regex lineRegexWithoutSpace(R"(^\>)");
line = std::regex_replace(line, lineRegexWithoutSpace, ""); line = std::regex_replace(line, lineRegexWithoutSpace, "");
if (!line.empty()) if (!line.empty())

View File

@@ -39,7 +39,7 @@ public:
void void
Parse(std::string& line) override Parse(std::string& line) override
{ {
static std::regex re("(?!.*`.*|.*<code>.*)\\~\\~(?!.*`.*|.*<\\/code>.*)([^\\~]*)\\~\\~(?!.*`.*|.*<\\/code>.*)"); static std::regex re(R"((?!.*`.*|.*<code>.*)\~\~(?!.*`.*|.*<\/code>.*)([^\~]*)\~\~(?!.*`.*|.*<\/code>.*))");
static std::string replacement = "<s>$1</s>"; static std::string replacement = "<s>$1</s>";
line = std::regex_replace(line, re, replacement); line = std::regex_replace(line, re, replacement);

View File

@@ -43,8 +43,8 @@ public:
{ {
static std::vector<std::regex> res static std::vector<std::regex> res
{ {
std::regex{"(?!.*`.*|.*<code>.*)\\*\\*(?!.*`.*|.*<\\/code>.*)([^\\*\\*]*)\\*\\*(?!.*`.*|.*<\\/code>.*)"}, std::regex{R"((?!.*`.*|.*<code>.*)\*\*(?!.*`.*|.*<\/code>.*)([^\*\*]*)\*\*(?!.*`.*|.*<\/code>.*))"},
std::regex{"(?!.*`.*|.*<code>.*)__(?!.*`.*|.*<\\/code>.*)([^__]*)__(?!.*`.*|.*<\\/code>.*)"} std::regex{R"((?!.*`.*|.*<code>.*)__(?!.*`.*|.*<\/code>.*)([^__]*)__(?!.*`.*|.*<\/code>.*))"}
}; };
static std::string replacement = "<strong>$1</strong>"; static std::string replacement = "<strong>$1</strong>";
for (const auto& re : res) for (const auto& re : res)