summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljsinterpreter.cpp
diff options
context:
space:
mode:
authorThomas Hartmann <Thomas.Hartmann@digia.com>2013-05-15 11:11:32 +0200
committerThomas Hartmann <Thomas.Hartmann@digia.com>2013-05-15 11:21:44 +0200
commit7d25b9090851d3db06bd0f91e7c3d05a80d1ca79 (patch)
tree605ab87c25ffdbaeb6f1437b6585e55c72900996 /src/libs/qmljs/qmljsinterpreter.cpp
parent3604bdbad29ba539bda5a4ac355838fd8554888f (diff)
downloadqt-creator-7d25b9090851d3db06bd0f91e7c3d05a80d1ca79.tar.gz
TypeDescriptionReader: Check for files that are not UTF8 encoded
We had a qmltypes file that was encoded in UTF16 and did not work. We should at least warn about it. Change-Id: I42555782ee16ddd25552f919845aa85ff1f3f636 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
Diffstat (limited to 'src/libs/qmljs/qmljsinterpreter.cpp')
-rw-r--r--src/libs/qmljs/qmljsinterpreter.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp
index ae8c100972..24d68d4948 100644
--- a/src/libs/qmljs/qmljsinterpreter.cpp
+++ b/src/libs/qmljs/qmljsinterpreter.cpp
@@ -39,6 +39,7 @@
#include <utils/qtcassert.h>
+#include <QApplication>
#include <QFile>
#include <QDir>
#include <QString>
@@ -1253,7 +1254,8 @@ CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::loadQmlTypes(const QFileInf
QByteArray contents = file.readAll();
file.close();
- parseQmlTypeDescriptions(contents, &newObjects, 0, &error, &warning);
+
+ parseQmlTypeDescriptions(contents, &newObjects, 0, &error, &warning, qmlTypeFile.absoluteFilePath());
} else {
error = file.errorString();
}
@@ -1272,15 +1274,28 @@ CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::loadQmlTypes(const QFileInf
return newObjects;
}
-void CppQmlTypesLoader::parseQmlTypeDescriptions(const QByteArray &xml,
+void CppQmlTypesLoader::parseQmlTypeDescriptions(const QByteArray &contents,
BuiltinObjects *newObjects,
QList<ModuleApiInfo> *newModuleApis,
QString *errorMessage,
- QString *warningMessage)
-{
+ QString *warningMessage, const QString &fileName)
+{
+ if (!contents.isEmpty()) {
+ unsigned char c = contents.at(0);
+ switch (c) {
+ case 0xfe:
+ case 0xef:
+ case 0xff:
+ case 0xee:
+ case 0x00:
+ qWarning() << QApplication::translate("CppQmlTypesLoader", "%1 seems not to be encoded in UTF8 or has a BOM.").arg(fileName);
+ default: break;
+ }
+ }
+
errorMessage->clear();
warningMessage->clear();
- TypeDescriptionReader reader(QString::fromUtf8(xml));
+ TypeDescriptionReader reader(QString::fromUtf8(contents));
if (!reader(newObjects, newModuleApis)) {
if (reader.errorMessage().isEmpty())
*errorMessage = QLatin1String("unknown error");