Commit 663bdbdd authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Codepaster: Compile with QT_NO_CAST_FROM_ASCII.



- Change the diff parsing to use QString reducing the
  conversions.

Change-Id: Id4d84947479a14d58b8a60157a98a56db5a89ddb
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent d2f8baad
......@@ -102,7 +102,7 @@ void CodePasterProtocol::fetch(const QString &id)
QTC_ASSERT(!m_fetchReply, return; )
QString hostName = m_page->hostName();
const QString httpPrefix = "http://";
const QString httpPrefix = QLatin1String("http://");
QString link;
// Did the user enter a complete URL instead of an id?
if (id.startsWith(httpPrefix)) {
......@@ -114,7 +114,7 @@ void CodePasterProtocol::fetch(const QString &id)
} else {
link = httpPrefix;
link.append(hostName);
link.append("/?format=raw&id=");
link.append(QLatin1String("/?format=raw&id="));
link.append(id);
m_fetchId = id;
}
......@@ -193,10 +193,10 @@ void CodePasterProtocol::fetchFinished()
if (error) {
content = m_fetchReply->errorString();
} else {
content = m_fetchReply->readAll();
content = QString::fromAscii(m_fetchReply->readAll()); // Codepaster does not support special characters.
if (debug)
qDebug() << content;
if (content.contains("<B>No such paste!</B>")) {
if (content.contains(QLatin1String("<B>No such paste!</B>"))) {
content = tr("No such paste");
error = true;
}
......
......@@ -49,7 +49,7 @@ ColumnIndicatorTextEdit::ColumnIndicatorTextEdit(QWidget *parent) :
setSizePolicy(sizePolicy);
int cmx = 0, cmy = 0, cmw = 0, cmh = 0;
getContentsMargins(&cmx, &cmy, &cmw, &cmh);
m_columnIndicator = QFontMetrics(font).width('W') * 100 + cmx + 1;
m_columnIndicator = QFontMetrics(font).width(QLatin1Char('W')) * 100 + cmx + 1;
m_columnIndicatorFont.setFamily(QString::fromUtf8("Times"));
m_columnIndicatorFont.setPointSizeF(7.0);
}
......@@ -63,7 +63,7 @@ void ColumnIndicatorTextEdit::paintEvent(QPaintEvent *event)
p.setPen(QPen(QColor(0xa0, 0xa0, 0xa0, 0xa0)));
p.drawLine(m_columnIndicator, 0, m_columnIndicator, viewport()->height());
int yOffset = verticalScrollBar()->value();
p.drawText(m_columnIndicator + 1, m_columnIndicatorFont.pointSize() - yOffset, "100");
p.drawText(m_columnIndicator + 1, m_columnIndicatorFont.pointSize() - yOffset, QLatin1String("100"));
}
} // namespace CodePaster
......@@ -3,6 +3,7 @@ TEMPLATE = lib
TARGET = CodePaster
include(../../qtcreatorplugin.pri)
include(cpaster_dependencies.pri)
DEFINES += QT_NO_CAST_FROM_ASCII
HEADERS += cpasterplugin.h \
settingspage.h \
protocol.h \
......
......@@ -256,7 +256,7 @@ void CodepasterPlugin::post(QString data, const QString &mimeType)
PasteView view(m_protocols, mimeType, 0);
view.setProtocol(m_settings->protocol);
const FileDataList diffChunks = splitDiffToFiles(data.toLatin1());
const FileDataList diffChunks = splitDiffToFiles(data);
const int dialogResult = diffChunks.isEmpty() ?
view.show(username, QString(), QString(), data) :
view.show(username, QString(), QString(), diffChunks);
......
......@@ -93,12 +93,12 @@ QString PasteView::comment() const
return comment;
}
QByteArray PasteView::content() const
QString PasteView::content() const
{
if (m_mode == PlainTextMode)
return m_ui.plainTextEdit->toPlainText().toUtf8();
return m_ui.plainTextEdit->toPlainText();
QByteArray newContent;
QString newContent;
for (int i = 0; i < m_ui.uiPatchList->count(); ++i) {
QListWidgetItem *item = m_ui.uiPatchList->item(i);
if (item->checkState() != Qt::Unchecked)
......@@ -157,7 +157,7 @@ int PasteView::show(const QString &user, const QString &description,
m_ui.uiPatchList->clear();
m_parts = parts;
m_mode = DiffChunkMode;
QByteArray content;
QString content;
foreach (const FileData &part, parts) {
QListWidgetItem *itm = new QListWidgetItem(part.filename, m_ui.uiPatchList);
itm->setCheckState(Qt::Checked);
......@@ -191,7 +191,7 @@ void PasteView::accept()
if (!Protocol::ensureConfiguration(protocol, this))
return;
const QByteArray data = content();
const QString data = content();
if (data.isEmpty())
return;
......
......@@ -69,7 +69,7 @@ public:
QString user() const;
QString description() const;
QString comment() const;
QByteArray content() const;
QString content() const;
QString protocol() const;
virtual void accept();
......
......@@ -68,9 +68,9 @@ void Settings::fromSettings(const QSettings *settings)
{
const QString rootKey = QLatin1String(groupC) + QLatin1Char('/');
#ifdef Q_OS_WIN
const QString defaultUser = qgetenv("USERNAME");
const QString defaultUser = QString::fromLocal8Bit(qgetenv("USERNAME"));
#else
const QString defaultUser = qgetenv("USER");
const QString defaultUser = QString::fromLocal8Bit(qgetenv("USER"));
#endif
username = settings->value(rootKey + QLatin1String(userNameKeyC), defaultUser).toString();
protocol = settings->value(rootKey + QLatin1String(defaultProtocolKeyC), PasteBinDotComProtocol::protocolName()).toString();
......
......@@ -44,13 +44,13 @@ QString CGI::encodeURL(const QString &rawText)
QByteArray::const_iterator it = utf.constBegin();
while (it != utf.constEnd()) {
char ch = *it;
const char ch = *it;
if (('A' <= ch && ch <= 'Z')
|| ('a' <= ch && ch <= 'z')
|| ('0' <= ch && ch <= '9'))
enc.append(*it);
enc.append(QLatin1Char(ch));
else if (ch == ' ')
enc.append('+');
enc.append(QLatin1Char('+'));
else {
switch (ch) {
case '-': case '_':
......@@ -58,14 +58,14 @@ QString CGI::encodeURL(const QString &rawText)
case '.': case '!':
case '~': case '*':
case '\'':
enc.append(ch);
enc.append(QLatin1Char(ch));
break;
default:
ushort c1 = (*it & 0xF0) >> 4;
ushort c2 = (*it & 0x0F);
enc.append('%');
enc.append(QChar(*(cgi_chars + c1)));
enc.append(QChar(*(cgi_chars + c2)));
enc.append(QLatin1Char('%'));
enc.append(QLatin1Char(*(cgi_chars + c1)));
enc.append(QLatin1Char(*(cgi_chars + c2)));
break;
}
}
......@@ -403,22 +403,22 @@ QString CGI::encodeHTML(const QString &rawText, int conversionFlags)
while (it != rawText.constEnd()) {
const char *html = unicodeToHTML((*it).unicode());
if (html) {
enc.append('&');
enc.append(html);
enc.append(';');
enc.append(QLatin1Char('&'));
enc.append(QLatin1String(html));
enc.append(QLatin1Char(';'));
} else if ((conversionFlags & CGI::LineBreaks)
&& ((*it).toLatin1() == '\n')) {
enc.append("<BR>\n");
enc.append(QLatin1String("<BR>\n"));
} else if ((conversionFlags & CGI::Spaces)
&& ((*it).toLatin1() == ' ')) {
enc.append("&nbsp;");
enc.append(QLatin1String("&nbsp;"));
} else if ((conversionFlags & CGI::Tabs)
&& ((*it).toLatin1() == '\t')) {
enc.append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
enc.append(QLatin1String("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"));
} else if ((*it).unicode() > 0x00FF) {
enc.append("&#");
enc.append(QLatin1String("&#"));
enc.append(QString::number((*it).unicode()));
enc.append(';');
enc.append(QLatin1Char(';'));
} else {
enc.append(*it);
}
......
......@@ -34,25 +34,24 @@
#include <QtCore/QRegExp>
FileDataList splitDiffToFiles(const QByteArray &data)
FileDataList splitDiffToFiles(const QString &strData)
{
FileDataList ret;
QString strData = data;
QString splitExpression;
if (data.contains("==== ") && data.contains(" ====\n")) {
if (strData.contains(QLatin1String("==== ")) && strData.contains(QLatin1String(" ====\n"))) {
// Perforce diff
splitExpression = "==== ([^\\n\\r]+) - ([^\\n\\r]+) ====";
splitExpression = QLatin1String("==== ([^\\n\\r]+) - ([^\\n\\r]+) ====");
} else if (data.contains("--- ") && data.contains("\n+++ ")) {
} else if (strData.contains(QLatin1String("--- ")) && strData.contains(QLatin1String("\n+++ "))) {
// Unified contextual diff
splitExpression = "\\-\\-\\- ([^\\n\\r]*)"
"\\n\\+\\+\\+ ([^\\n\\r]*)";
splitExpression = QLatin1String("\\-\\-\\- ([^\\n\\r]*)"
"\\n\\+\\+\\+ ([^\\n\\r]*)");
} else if (data.contains("*** ") && data.contains("\n--- ")) {
} else if (strData.contains(QLatin1String("*** ")) && strData.contains(QLatin1String("\n--- "))) {
// Copied contextual diff
splitExpression = "\\*\\*\\* ([^\\n\\r]*) [0-9\\-]* [0-9:\\.]*[^\\n\\r]*"
"\\n\\-\\-\\- ([^\\n\\r]*) [0-9\\-]* [0-9:\\.]*[^\\n\\r]*";
splitExpression = QLatin1String("\\*\\*\\* ([^\\n\\r]*) [0-9\\-]* [0-9:\\.]*[^\\n\\r]*"
"\\n\\-\\-\\- ([^\\n\\r]*) [0-9\\-]* [0-9:\\.]*[^\\n\\r]*");
} else {
return FileDataList();
......@@ -60,7 +59,7 @@ FileDataList splitDiffToFiles(const QByteArray &data)
int splitIndex = 0, previousSplit = -1;
QRegExp splitExpr(splitExpression);
QString filename, content;
QString filename;
// The algorithm works like this:
// On the first match we only get the filename of the first patch part
// On the second match (if any) we get the diff content, and the name of the next file patch
......@@ -68,7 +67,7 @@ FileDataList splitDiffToFiles(const QByteArray &data)
while (-1 != (splitIndex = splitExpr.indexIn(strData,splitIndex))) {
if (!filename.isEmpty()) {
QString content = strData.mid(previousSplit, splitIndex - previousSplit);
ret.append(FileData(filename, content.toLatin1()));
ret.append(FileData(filename, content));
}
// If the first index in not at the beginning of the file, then we know there's content
......@@ -76,7 +75,7 @@ FileDataList splitDiffToFiles(const QByteArray &data)
// a 'fake' filename.
if (previousSplit == -1 && splitIndex > 0 && filename.isEmpty()) {
QString content = strData.left(splitIndex);
ret.append(FileData("<Header information>", content.toLatin1()));
ret.append(FileData(QLatin1String("<Header information>"), content));
}
filename = splitExpr.cap(1);
......@@ -85,8 +84,8 @@ FileDataList splitDiffToFiles(const QByteArray &data)
}
// Append the last patch content
if (!filename.isEmpty()) {
QString content = strData.mid(previousSplit);
ret.append(FileData(filename, content.toLatin1()));
const QString content = strData.mid(previousSplit);
ret.append(FileData(filename, content));
}
return ret;
......
......@@ -39,15 +39,15 @@
struct FileData
{
FileData(const QString &f, const QByteArray &c)
FileData(const QString &f, const QString &c)
{ filename = f; content = c; }
QString filename;
QByteArray content;
QString content;
};
typedef QList<FileData> FileDataList;
FileDataList splitDiffToFiles(const QByteArray &data);
FileDataList splitDiffToFiles(const QString &data);
#endif // SPLITTER_H
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