mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Removed uneccessary for loop in markdown and url parsing.
This commit is contained in:
parent
252c9c8fae
commit
d343408749
|
@ -183,7 +183,7 @@ void ChatMessage::hideDate()
|
|||
|
||||
QString ChatMessage::detectMarkdown(const QString &str)
|
||||
{
|
||||
QString out;
|
||||
QString out = str;
|
||||
|
||||
// Create regex for certain markdown syntax
|
||||
QRegExp exp("(\\*\\*)([^\\*\\*]{2,})(\\*\\*)" // Bold **text**
|
||||
|
@ -196,12 +196,6 @@ QString ChatMessage::detectMarkdown(const QString &str)
|
|||
"|(\\`)([^\\`]{2,})(\\`)" // Codeblock `text`
|
||||
);
|
||||
|
||||
// Support for multi-line text
|
||||
QStringList messageLines = str.split("\n");
|
||||
QStringList outLines;
|
||||
for (int i = 0; i < messageLines.size(); ++i)
|
||||
{
|
||||
out = messageLines.at(i);
|
||||
int offset = 0;
|
||||
while ((offset = exp.indexIn(out, offset)) != -1)
|
||||
{
|
||||
|
@ -242,14 +236,13 @@ QString ChatMessage::detectMarkdown(const QString &str)
|
|||
} else
|
||||
offset += snippet.length();
|
||||
}
|
||||
outLines.push_back(out);
|
||||
}
|
||||
return outLines.join("\n");
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QString ChatMessage::detectAnchors(const QString &str)
|
||||
{
|
||||
QString out;
|
||||
QString out = str;
|
||||
|
||||
// detect URIs
|
||||
QRegExp exp("("
|
||||
|
@ -261,12 +254,7 @@ QString ChatMessage::detectAnchors(const QString &str)
|
|||
"|(?:\\b)(mailto:\\S+@\\S+\\.\\S+)" //@mail link
|
||||
"|(?:\\b)(tox:\\S+@\\S+)"); // starts with `tox` then : and only alpha-digits till the end
|
||||
// also accepts tox:agilob@net as simplified TOX ID
|
||||
//support for multi-line text
|
||||
QStringList messageLines = str.split("\n");
|
||||
QStringList outLines;
|
||||
for (int i = 0; i < messageLines.size(); ++i)
|
||||
{
|
||||
out = messageLines.at(i);
|
||||
|
||||
int offset = 0;
|
||||
while ((offset = exp.indexIn(out, offset)) != -1)
|
||||
{
|
||||
|
@ -286,9 +274,8 @@ QString ChatMessage::detectAnchors(const QString &str)
|
|||
out.replace(offset, exp.cap().length(), htmledUrl);
|
||||
offset += htmledUrl.length();
|
||||
}
|
||||
outLines.push_back(out);
|
||||
}
|
||||
return outLines.join("\n");
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QString ChatMessage::detectQuotes(const QString& str, MessageType type)
|
||||
|
|
Loading…
Reference in New Issue
Block a user