Commit e584a432 authored by JanKusanagi's avatar JanKusanagi

More small optimizations

parent 21f3f475
......@@ -460,25 +460,26 @@ QString MiscHelpers::cleanupHtml(QString originalHtml)
{
QString cleanHtml = originalHtml;
cleanHtml.replace("\n", " "); // Remove line breaks, as that results in server error 500
// Remove line breaks, as that results in server error 500
cleanHtml.replace(QStringLiteral("\n"), QStringLiteral(" "));
QRegExp doctypeRE("<!DOCTYPE.*>");
QRegExp doctypeRE(QStringLiteral("<!DOCTYPE.*>"));
doctypeRE.setMinimal(true);
cleanHtml.remove(doctypeRE);
QRegExp headRE("<html><head>.*</head>");
QRegExp headRE(QStringLiteral("<html><head>.*</head>"));
headRE.setMinimal(true);
cleanHtml.remove(headRE);
QRegExp bodyRE("<body style.*>");
QRegExp bodyRE(QStringLiteral("<body style.*>"));
bodyRE.setMinimal(true);
cleanHtml.remove(bodyRE);
//////////////////////////////////////// Remove <span style=...> from links
QRegExp linkStyleRE("<a href=.*>.*</a>");
QRegExp linkStyleRE(QStringLiteral("<a href=.*>.*</a>"));
linkStyleRE.setMinimal(true);
QRegExp spanRE("<span style=.*>(.*)</span>"); // FIXME: remove ONLY color info
QRegExp spanRE(QStringLiteral("<span style=.*>(.*)</span>")); // FIXME: remove ONLY color info
spanRE.setMinimal(true);
int pos = 0;
......@@ -497,26 +498,26 @@ QString MiscHelpers::cleanupHtml(QString originalHtml)
}
////////////////////////////////////// Remove style from <ul> <ol> and <li>
QRegExp ulStyleRE("<ul style.*>");
QRegExp ulStyleRE(QStringLiteral("<ul style.*>"));
ulStyleRE.setMinimal(true);
cleanHtml.replace(ulStyleRE, "<ul>");
cleanHtml.replace(ulStyleRE, QStringLiteral("<ul>"));
QRegExp olStyleRE("<ol style.*>");
QRegExp olStyleRE(QStringLiteral("<ol style.*>"));
olStyleRE.setMinimal(true);
cleanHtml.replace(olStyleRE, "<ol>");
cleanHtml.replace(olStyleRE, QStringLiteral("<ol>"));
QRegExp liStyleRE("<li style.*>");
QRegExp liStyleRE(QStringLiteral("<li style.*>"));
liStyleRE.setMinimal(true);
cleanHtml.replace(liStyleRE, "<li>");
cleanHtml.replace(liStyleRE, QStringLiteral("<li>"));
// FIXME: Maybe try to remove background colors from <p> elements
// Remove these elements created by some QTextBlocks
cleanHtml.remove("<!--StartFragment-->");
cleanHtml.remove("<!--EndFragment-->");
cleanHtml.remove(QStringLiteral("<!--StartFragment-->"));
cleanHtml.remove(QStringLiteral("<!--EndFragment-->"));
cleanHtml.remove("</body></html>");
cleanHtml.remove(QStringLiteral("</body></html>"));
return cleanHtml.trimmed();
}
......@@ -529,12 +530,12 @@ QString MiscHelpers::htmlWithoutLinks(QString originalHtml)
{
QString cleanHtml = originalHtml;
QRegExp linksRE("<a href=.*>");
QRegExp linksRE(QStringLiteral("<a href=.*>"));
linksRE.setMinimal(true);
linksRE.setCaseSensitivity(Qt::CaseInsensitive);
cleanHtml.remove(linksRE);
cleanHtml.remove("</a>", Qt::CaseInsensitive);
cleanHtml.remove(QStringLiteral("</a>"), Qt::CaseInsensitive);
return cleanHtml;
......@@ -546,12 +547,12 @@ QString MiscHelpers::htmlToPlainText(QString html, int charLimit)
textDocument.setHtml(html);
QString plainText = textDocument.toPlainText().trimmed();
plainText.replace("\n", " ");
plainText.replace(QStringLiteral("\n"), QStringLiteral(" "));
plainText = plainText.trimmed();
if (charLimit != 0 && plainText.length() > charLimit)
{
plainText = plainText.left(charLimit).trimmed() + "...";
plainText = plainText.left(charLimit).trimmed() + QStringLiteral("...");
}
return plainText;
......@@ -633,7 +634,7 @@ QString MiscHelpers::mediaHtmlBase(QString postType,
"<td align=center>"
"<a title=\"" + tooltipMessage + "\" href";
if (postType == "image")
if (postType == QStringLiteral("image"))
{
html.append("=\"image:/" + attachmentFilename + "\" >");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment