summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpppreprocessor.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2013-11-14 10:59:46 +0100
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-11-18 13:03:08 +0100
commitc1225ea3f4bd534f8edc982e77d300c6e93219c7 (patch)
tree8526f1129b2e7d9e7ecd654a2f16aa664ef8adea /src/plugins/cpptools/cpppreprocessor.cpp
parent2f040fc6adea6606a0d8324be09da89f35ed0c62 (diff)
downloadqt-creator-c1225ea3f4bd534f8edc982e77d300c6e93219c7.tar.gz
CppTools: Use editor manager's codec as fallback
...for reading not already opened files. This partly reverts commit f7c68f6. In case TextFileFormat::detect() fails, the user configurable editor manager's codec is used instead of QTextCodec::codecForLocale(). Adds also a qWarning() to easier detect encoding errors. Task-number: QTCREATORBUG-10378 Change-Id: I0fa4e6b898ed090d85414ce2a001f11b115a42d3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cpppreprocessor.cpp')
-rw-r--r--src/plugins/cpptools/cpppreprocessor.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/plugins/cpptools/cpppreprocessor.cpp b/src/plugins/cpptools/cpppreprocessor.cpp
index 56668fe644..f8d14bf123 100644
--- a/src/plugins/cpptools/cpppreprocessor.cpp
+++ b/src/plugins/cpptools/cpppreprocessor.cpp
@@ -2,11 +2,15 @@
#include "cppmodelmanager.h"
+#include <coreplugin/editormanager/editormanager.h>
+
+#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <utils/textfileformat.h>
#include <QCoreApplication>
#include <QCryptographicHash>
+#include <QTextCodec>
/*!
* \class CppTools::Internal::CppPreprocessor
@@ -30,7 +34,8 @@ CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager,
m_modelManager(modelManager),
m_dumpFileNameWhileParsing(dumpFileNameWhileParsing),
m_preprocess(this, &m_env),
- m_revision(0)
+ m_revision(0),
+ m_defaultCodec(Core::EditorManager::defaultTextCodec())
{
m_preprocess.setKeepComments(true);
}
@@ -41,7 +46,8 @@ CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager, const S
m_modelManager(modelManager),
m_dumpFileNameWhileParsing(dumpFileNameWhileParsing),
m_preprocess(this, &m_env),
- m_revision(0)
+ m_revision(0),
+ m_defaultCodec(Core::EditorManager::defaultTextCodec())
{
m_preprocess.setKeepComments(true);
}
@@ -182,9 +188,14 @@ void CppPreprocessor::getFileContents(const QString &absoluteFilePath,
return;
}
- QString errStr;
- if (contents)
- Utils::TextFileFormat::readFileUTF8(absoluteFilePath, contents, &errStr);
+ if (contents) {
+ QString error;
+ if (Utils::TextFileFormat::readFileUTF8(absoluteFilePath, m_defaultCodec, contents, &error)
+ != Utils::TextFileFormat::ReadSuccess) {
+ qWarning("Error reading file \"%s\": \"%s\".", qPrintable(absoluteFilePath),
+ qPrintable(error));
+ }
+ }
if (revision)
*revision = 0;
}