mirror of
https://github.com/progsource/maddy.git
synced 2026-03-25 16:00:39 +01:00
style: make regex strings more readable
This commit is contained in:
@@ -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 = "<input type=\"checkbox\"/>";
|
||||
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\"/>";
|
||||
line = std::regex_replace(line, boxRegex, boxReplacement);
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
void
|
||||
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>";
|
||||
|
||||
line = std::regex_replace(line, re, replacement);
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
void
|
||||
Parse(std::string& line) override
|
||||
{
|
||||
static std::regex re("\\!\\[([^\\]]*)\\]\\(([^\\]]*)\\)");
|
||||
static std::regex re(R"(\!\[([^\]]*)\]\(([^\]]*)\))");
|
||||
static std::string replacement = "<img src=\"$2\" alt=\"$1\"/>";
|
||||
|
||||
line = std::regex_replace(line, re, replacement);
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
void
|
||||
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>";
|
||||
line = std::regex_replace(line, re, replacement);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
void
|
||||
Parse(std::string& line) override
|
||||
{
|
||||
static std::regex re("\\[([^\\]]*)\\]\\(([^\\]]*)\\)");
|
||||
static std::regex re(R"(\[([^\]]*)\]\(([^\]]*)\))");
|
||||
static std::string replacement = "<a href=\"$2\">$1</a>";
|
||||
|
||||
line = std::regex_replace(line, re, replacement);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
void
|
||||
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>";
|
||||
|
||||
line = std::regex_replace(line, re, replacement);
|
||||
|
||||
@@ -43,8 +43,8 @@ public:
|
||||
{
|
||||
static std::vector<std::regex> res
|
||||
{
|
||||
std::regex{"(?!.*`.*|.*<code>.*)\\*\\*(?!.*`.*|.*<\\/code>.*)([^\\*\\*]*)\\*\\*(?!.*`.*|.*<\\/code>.*)"},
|
||||
std::regex{"(?!.*`.*|.*<code>.*)__(?!.*`.*|.*<\\/code>.*)([^__]*)__(?!.*`.*|.*<\\/code>.*)"}
|
||||
std::regex{R"((?!.*`.*|.*<code>.*)\*\*(?!.*`.*|.*<\/code>.*)([^\*\*]*)\*\*(?!.*`.*|.*<\/code>.*))"},
|
||||
std::regex{R"((?!.*`.*|.*<code>.*)__(?!.*`.*|.*<\/code>.*)([^__]*)__(?!.*`.*|.*<\/code>.*))"}
|
||||
};
|
||||
static std::string replacement = "<strong>$1</strong>";
|
||||
for (const auto& re : res)
|
||||
|
||||
Reference in New Issue
Block a user