Commit 34cecc60 authored by rwlbuis@webkit.org's avatar rwlbuis@webkit.org
Browse files

[BlackBerry] Use StringBuilder more in BlackBerry RSS classes

https://bugs.webkit.org/show_bug.cgi?id=96820

Reviewed by Antonio Gomes.

Use append/appendLiteral where possible.

* platform/MIMETypeRegistry.cpp:
(WebCore::mimeTypeAssociationMap):
* platform/network/blackberry/rss/RSSAtomParser.cpp:
(WebCore::RSSAtomParser::parseContent):
(WebCore::RSSAtomParser::parseAuthor):
* platform/network/blackberry/rss/RSSGenerator.cpp:
(WebCore::RSSGenerator::generateHtml):
* platform/network/blackberry/rss/RSSParserBase.cpp:
(WebCore::textFromXMLAttr):
(WebCore::textFromXMLNode):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@128647 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b6b4aac1
2012-09-14 Rob Buis <rbuis@rim.com>
[BlackBerry] Use StringBuilder more in BlackBerry RSS classes
https://bugs.webkit.org/show_bug.cgi?id=96820
Reviewed by Antonio Gomes.
Use append/appendLiteral where possible.
* platform/MIMETypeRegistry.cpp:
(WebCore::mimeTypeAssociationMap):
* platform/network/blackberry/rss/RSSAtomParser.cpp:
(WebCore::RSSAtomParser::parseContent):
(WebCore::RSSAtomParser::parseAuthor):
* platform/network/blackberry/rss/RSSGenerator.cpp:
(WebCore::RSSGenerator::generateHtml):
* platform/network/blackberry/rss/RSSParserBase.cpp:
(WebCore::textFromXMLAttr):
(WebCore::textFromXMLNode):
2012-09-14 Alexandru Chiculita <achicu@adobe.com>
 
[CSS Shaders] Enable anti-aliasing on the FECustomFilter
......@@ -638,7 +638,7 @@ static const MIMETypeAssociationMap& mimeTypeAssociationMap()
mimeTypeMap = new MIMETypeAssociationMap;
mimeTypeMap->add(ASCIILiteral("image/x-ms-bmp"), ASCIILiteral("image/bmp")));
mimeTypeMap->add(ASCIILiteral("image/x-ms-bmp"), ASCIILiteral("image/bmp"));
mimeTypeMap->add(ASCIILiteral("image/x-windows-bmp"), ASCIILiteral("image/bmp"));
mimeTypeMap->add(ASCIILiteral("image/x-bmp"), ASCIILiteral("image/bmp"));
mimeTypeMap->add(ASCIILiteral("image/x-bitmap"), ASCIILiteral("image/bmp"));
......
......@@ -22,6 +22,7 @@
#include "BlackBerryPlatformAssert.h"
#include "libxml/parser.h"
#include "libxml/xmlwriter.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
......@@ -231,7 +232,7 @@ String RSSAtomParser::parseContent(const String& base, xmlNode* node)
BLACKBERRY_ASSERT(node);
// Why does Blackberry have its own RSS parser?
// FIXME: content should be a StringBuilder.
String content;
String type = "default";
String src;
......@@ -248,9 +249,10 @@ String RSSAtomParser::parseContent(const String& base, xmlNode* node)
if (!src.isEmpty()) {
if (isRelativePath(src))
src = base + "/" + src;
content += "<a href=\"";
content += src + "\">" + src + "</a>";
return content;
StringBuilder builder;
builder.appendLiteral("<a href=\"");
builder.append(src + "\">" + src + "</a>");
return builder.toString();
}
if (type == "text" || type.startsWith("text/"))
......@@ -263,14 +265,16 @@ String RSSAtomParser::parseContent(const String& base, xmlNode* node)
if (cur && cur->type == XML_ELEMENT_NODE) {
// Encoding of buffer is utf-8.
xmlNodeDump(buffer, cur->doc, cur, 0, 0);
StringBuilder builder;
if (!base.isEmpty()) {
content += "<base href='";
content += m_url.baseAsString();
content += "/";
content += base;
content += "/' />";
builder.appendLiteral("<base href='");
builder.append(m_url.baseAsString());
builder.appendLiteral("/");
builder.append(base);
builder.appendLiteral("/' />");
}
content += (const char*)xmlBufferContent(buffer);
builder.append((const char*)xmlBufferContent(buffer));
content = builder.toString();
}
xmlBufferFree(buffer);
} else if (type.endsWith("+xml") || type.endsWith("/xml"))
......@@ -300,9 +304,9 @@ String RSSAtomParser::parseAuthor(xmlNode* node)
}
if (!email.isEmpty()) {
username += " (";
username += email;
username += ")";
username = username + " (";
username = username + email;
username = username + ")";
}
return username;
......
......@@ -23,6 +23,7 @@
#include "RSSParserBase.h"
#include <wtf/text/CString.h>
#include <wtf/text/StringBuilder.h>
namespace WebCore {
......@@ -39,131 +40,131 @@ RSSGenerator::~RSSGenerator()
String RSSGenerator::generateHtml(RSSFeed* feed)
{
String rc;
rc += "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />";
rc += "<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable= no\">";
rc += "<title>";
StringBuilder builder;
builder.appendLiteral("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />");
builder.appendLiteral("<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable= no\">");
builder.appendLiteral("<title>");
if (!feed->m_title.isEmpty())
rc += feed->m_title;
builder.append(feed->m_title);
else if (!feed->m_link.isEmpty())
rc += feed->m_link;
builder.append(feed->m_link);
else
rc += s_defaultFeedTitle;
builder.append(s_defaultFeedTitle);
rc += "</title></head><body>";
builder.appendLiteral("</title></head><body>");
rc += "<h2>";
builder.appendLiteral("<h2>");
if (!feed->m_link.isEmpty()) {
rc += "<a href=\"";
rc += feed->m_link;
rc += "\">";
builder.appendLiteral("<a href=\"");
builder.append(feed->m_link);
builder.appendLiteral("\">");
}
if (!feed->m_title.isEmpty())
rc += feed->m_title;
builder.append(feed->m_title);
else
rc += s_defaultFeedTitle;
builder.append(s_defaultFeedTitle);
if (!feed->m_link.isEmpty())
rc += "</a>";
builder.appendLiteral("</a>");
rc += "</h2>";
builder.appendLiteral("</h2>");
if (!feed->m_description.isEmpty()) {
rc += "<p>";
rc += feed->m_description;
rc += "</p>";
builder.appendLiteral("<p>");
builder.append(feed->m_description);
builder.appendLiteral("</p>");
}
for (unsigned i = 0; i < feed->m_items.size(); ++i) {
RSSItem* item = feed->m_items[i];
String articleName;
rc += "<div id=\"";
rc += articleName;
rc += "\" class=\"article\">\n<a href=\"";
builder.appendLiteral("<div id=\"");
builder.append(articleName);
builder.appendLiteral("\" class=\"article\">\n<a href=\"");
if (!item->m_link.isEmpty())
rc += item->m_link.utf8(true).data();
rc += "\"><b>";
builder.append(item->m_link.utf8(true).data());
builder.appendLiteral("\"><b>");
if (!item->m_title.isEmpty())
rc += item->m_title.utf8(true).data();
builder.append(item->m_title.utf8(true).data());
else
rc += s_defaultEntryTitle;
rc += "</b></a>\n<br />";
builder.append(s_defaultEntryTitle);
builder.appendLiteral("</b></a>\n<br />");
if (!item->m_author.isEmpty()) {
rc += i18n("By");
rc += " <b>";
rc += item->m_author.utf8(true).data();
rc += "</b> ";
builder.append(i18n("By"));
builder.appendLiteral(" <b>");
builder.append(item->m_author.utf8(true).data());
builder.appendLiteral("</b> ");
} else {
if (!feed->m_author.isEmpty()) {
rc += i18n("By");
rc += " <b>";
rc += feed->m_author.utf8(true).data();
rc += "</b> ";
builder.append(i18n("By"));
builder.appendLiteral(" <b>");
builder.append(feed->m_author.utf8(true).data());
builder.appendLiteral("</b> ");
}
}
if (!item->m_categories.isEmpty()) {
if (!item->m_author.isEmpty())
rc += i18n("under ");
builder.append(i18n("under "));
else
rc += i18n("Under ");
builder.append(i18n("Under "));
for (unsigned i = 0; i < item->m_categories.size() ; ++i) {
rc += "<b>";
rc += item->m_categories[i].utf8(true).data();
rc += "</b>";
builder.appendLiteral("<b>");
builder.append(item->m_categories[i].utf8(true).data());
builder.appendLiteral("</b>");
if (i < item->m_categories.size() - 1)
rc += ", ";
builder.appendLiteral(", ");
}
}
rc += "<br />";
builder.appendLiteral("<br />");
if (!item->m_pubDate.isEmpty())
rc += item->m_pubDate.utf8(true).data();
builder.append(item->m_pubDate.utf8(true).data());
rc += "<br />";
builder.appendLiteral("<br />");
if (!item->m_description.isEmpty())
rc += item->m_description.utf8(true).data();
rc += "<br />";
builder.append(item->m_description.utf8(true).data());
builder.appendLiteral("<br />");
if (item->m_enclosure) {
rc += "<br />";
rc += "<a href=\"";
rc += item->m_enclosure->m_url;
rc += "\">";
rc += i18n("Embedded ");
builder.appendLiteral("<br />");
builder.appendLiteral("<a href=\"");
builder.append(item->m_enclosure->m_url);
builder.appendLiteral("\">");
builder.append(i18n("Embedded "));
RSSEnclosure::Type type = item->m_enclosure->typeInEnum();
switch (type) {
case RSSEnclosure::TypeImage:
rc += i18n("Image");
builder.append(i18n("Image"));
break;
case RSSEnclosure::TypeAudio:
rc += i18n("Audio");
builder.append(i18n("Audio"));
break;
case RSSEnclosure::TypeVideo:
rc += i18n("Video");
builder.append(i18n("Video"));
break;
case RSSEnclosure::TypeApplication:
default:
rc += i18n("Unknown Content");
builder.append(i18n("Unknown Content"));
break;
}
rc += i18n(" Source: ");
rc += item->m_enclosure->suggestedName();
rc += "</a><br /><br />";
builder.append(i18n(" Source: "));
builder.append(item->m_enclosure->suggestedName());
builder.appendLiteral("</a><br /><br />");
}
rc += "<br /></div>\n";
builder.appendLiteral("<br /></div>\n");
}
rc += "</body></html>\n";
builder.appendLiteral("</body></html>\n");
return rc;
return builder.toString();
}
} // namespace WebCore
......@@ -21,6 +21,7 @@
#include "libxml/parser.h"
#include "libxml/xmlwriter.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
......@@ -110,14 +111,14 @@ String textFromXMLAttr(xmlAttr* attr)
if (!attr)
return emptyString();
String text;
StringBuilder text;
for (xmlNode* node = attr->children; node; node = node->next) {
if (node->type == XML_TEXT_NODE)
text += reinterpret_cast<const char*>(node->content);
text.append(reinterpret_cast<const char*>(node->content));
}
return text.stripWhiteSpace();
return text.toString().stripWhiteSpace();
}
String textFromXMLNode(xmlNode* node)
......@@ -125,14 +126,14 @@ String textFromXMLNode(xmlNode* node)
if (!node)
return emptyString();
String text;
StringBuilder text;
for (node = node->children; node; node = node->next) {
if ((node->type == XML_TEXT_NODE) || (node->type == XML_CDATA_SECTION_NODE))
text += reinterpret_cast<const char*>(node->content);
text.append(reinterpret_cast<const char*>(node->content));
}
return text.stripWhiteSpace();
return text.toString().stripWhiteSpace();
}
} // namespace WebCore
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