Commit d5df3dfc authored by JanKusanagi's avatar JanKusanagi

Further QStringLiteral optimizations

parent 98ab46e5
......@@ -361,12 +361,12 @@ QStringList MiscHelpers::htmlWithReplacedImages(QString originalHtml, int postWi
//qDebug() << "MiscHelpers::htmlWithReplacedImages(); HTML contains some <img> tags...";
QString newHtml = originalHtml;
newHtml.remove("\n"); // Remove in case misbehaving applications added any
newHtml.remove(QStringLiteral("\n")); // Remove in case misbehaving applications added any
QStringList imageList;
QString imgSrc;
QRegExp regExp("\\<img(.+)src=(\"|\\')([^\"\\']+)(\"|\\')(.*)\\>");
QRegExp regExp(QStringLiteral("\\<img(.+)src=(\"|\\')([^\"\\']+)(\"|\\')(.*)\\>"));
regExp.setMinimal(true);
int matchedLength = 0;
......@@ -401,20 +401,23 @@ QStringList MiscHelpers::htmlWithReplacedImages(QString originalHtml, int postWi
// add to the list, and replace HTML
if (!imgSrc.isEmpty())
{
// If the url had parameters, they _might_ have &amp; in place of "&"
imgSrc.replace("&amp;", "&"); // Put them back
// If the URL had parameters, they _might_ have &amp; in place of "&"
imgSrc.replace(QStringLiteral("&amp;"),
QStringLiteral("&")); // Put them back
// Check if http part (scheme) is missing from URL, and add it
if (!imgSrc.startsWith("http"))
if (!imgSrc.startsWith(QStringLiteral("http")))
{
imgSrc.prepend("http:");
imgSrc.prepend(QStringLiteral("http:"));
}
// Add URL to list
imageList.append(imgSrc);
QString cachedImageFilename = getCachedImageFilename(imgSrc);
const QString cachedImageFilename = getCachedImageFilename(imgSrc);
// Determine optimal image size
int imageWidth = getImageWidth(cachedImageFilename);
if (imageWidth <= 0) // If we still don't have a cached file,
{
......@@ -425,13 +428,18 @@ QStringList MiscHelpers::htmlWithReplacedImages(QString originalHtml, int postWi
if (imageWidth > postWidth - 32)
{
// Some margins, to account for a scrollbar or a tab space before the image
// FIXME
imageWidth = postWidth - 32;
}
newHtml.replace(stringPos,
matchedLength,
"<img src=\"" + cachedImageFilename + "\" "
"width=\"" + QString("%1").arg(imageWidth) + "\" />");
QStringLiteral("<img src=\"")
+ cachedImageFilename
+ QStringLiteral("\" width=\"")
+ QString("%1").arg(imageWidth)
+ QStringLiteral("\" />"));
}
stringPos += matchedLength; // FIXME: error control
......
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