diff --git a/src/textutil.cpp b/src/textutil.cpp
index e2535a2d6..cc0077b8d 100644
--- a/src/textutil.cpp
+++ b/src/textutil.cpp
@@ -191,33 +191,37 @@ QString TextUtil::rich2plain(const QString &in, bool collapseSpaces)
QString TextUtil::resolveEntities(const QStringView &in)
{
QString out;
+ out.reserve(in.length());
- for (int i = 0; i < int(in.length()); ++i) {
- if (in[i] == '&') {
- // find a semicolon
- ++i;
- int n = in.indexOf(';', i);
- if (n == -1)
- break;
- auto type = in.mid(i, (n - i));
-
- i = n; // should be n+1, but we'll let the loop increment do it
-
- if (type == QLatin1String { "amp" })
- out += '&';
- else if (type == QLatin1String { "lt" })
- out += '<';
- else if (type == QLatin1String { "gt" })
- out += '>';
- else if (type == QLatin1String { "quot" })
- out += '\"';
- else if (type == QLatin1String { "apos" })
- out += '\'';
- else if (type == QLatin1String { "nbsp" })
- out += char(0xa0);
- } else {
+ for (qsizetype i = 0; i < int(in.length()); i++) {
+ if (in[i] != '&') {
out += in[i];
+ continue;
}
+ // find a semicolon
+ qsizetype n = in.indexOf(';', i+1);
+ if (n == -1) {
+ out += in[i];
+ continue;
+ }
+ auto type = in.mid(i+1, (n - (i+1)));
+ if (type == QLatin1String { "amp" })
+ out += '&';
+ else if (type == QLatin1String { "lt" })
+ out += '<';
+ else if (type == QLatin1String { "gt" })
+ out += '>';
+ else if (type == QLatin1String { "quot" })
+ out += '\"';
+ else if (type == QLatin1String { "apos" })
+ out += '\'';
+ else if (type == QLatin1String { "nbsp" })
+ out += char(0xa0);
+ else {
+ out += in[i];
+ continue;
+ }
+ i = n; // should be n+1, but we'll let the loop increment do it
}
return out;
@@ -452,7 +456,7 @@ QString TextUtil::linkify(const QString &in)
#else
auto linkColor = ColorOpt::instance()->color("options.ui.look.colors.messages.link");
// we have visited link as well but it's no applicable to QTextEdit or we have to track visited manually
- linked = QString("").arg(href, linkColor.name());
+ linked = QString(R"()").arg(href, linkColor.name());
#endif
linked += (escape(link) + "" + escape(pre.mid(cutoff)));
out.replace(x1, len, linked);
@@ -592,17 +596,16 @@ QString TextUtil::img2title(const QString &in)
QString TextUtil::legacyFormat(const QString &in)
{
-
// enable *bold* stuff
// //old code
- // out=out.replace(QRegularExpression("(^[^<>\\s]*|\\s[^<>\\s]*)\\*(\\S+)\\*([^<>\\s]*\\s|[^<>\\s]*$)"),"\\1*\\2*\\3");
- // out=out.replace(QRegularExpression("(^[^<>\\s\\/]*|\\s[^<>\\s\\/]*)\\/([^\\/\\s]+)\\/([^<>\\s\\/]*\\s|[^<>\\s\\/]*$)"),"\\1/\\2/\\3");
- // out=out.replace(QRegularExpression("(^[^<>\\s]*|\\s[^<>\\s]*)_(\\S+)_([^<>\\s]*\\s|[^<>\\s]*$)"),"\\1_\\2_\\3");
+ // out=out.replace(QRegularExpression(R"((^[^<>\s]*|\s[^<>\s]*)\*(\S+)\*([^<>\s]*\s|[^<>\s]*$))"), "\\1*\\2*\\3");
+ // out=out.replace(QRegularExpression(R"((^[^<>\s\/]*|\s[^<>\s\/]*)\/([^\/\s]+)\/([^<>\s\/]*\s|[^<>\s\/]*$))"), "\\1/\\2/\\3");
+ // out=out.replace(QRegularExpression(R"((^[^<>\s]*|\s[^<>\s]*)_(\S+)_([^<>\s]*\s|[^<>\s]*$))"), "\\1_\\2_\\3");
QString out = in;
- out = out.replace(QRegularExpression("(^|\\s|>)_(\\S+)_(?=<|\\s|$)"), "\\1_\\2_"); // underline inside _text_
- out = out.replace(QRegularExpression("(^|\\s|>)\\*(\\S+)\\*(?=<|\\s|$)"), "\\1*\\2*"); // bold *text*
- out = out.replace(QRegularExpression("(^|\\s|>)\\/(\\S+)\\/(?=<|\\s|$)"), "\\1/\\2/"); // italic /text/
+ out = out.replace(QRegularExpression(R"((^|\s|>)_(\S+)_(?=<|\s|$))"), "\\1_\\2_"); // underline inside _text_
+ out = out.replace(QRegularExpression(R"((^|\s|>)\*(\S+)\*(?=<|\s|$))"), "\\1*\\2*"); // bold *text*
+ out = out.replace(QRegularExpression(R"((^|\s|>)\/(\S+)\/(?=<|\s|$))"), "\\1/\\2/"); // italic /text/
return out;
}