summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpppreprocessor.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2013-08-19 15:47:51 +0200
committerErik Verbruggen <erik.verbruggen@digia.com>2013-09-11 09:43:14 +0200
commitf7c68f6baf104729e8d2fb3a0693b3c59928f8d3 (patch)
treefc0b7227fb28425b65f194d1f6d58bb4d5f53299 /src/plugins/cpptools/cpppreprocessor.cpp
parenteebb1dfcf4d0d4a391a77ab9e095188f63b616e4 (diff)
downloadqt-creator-f7c68f6baf104729e8d2fb3a0693b3c59928f8d3.tar.gz
C++: change working-copy to work on UTF-8 encoded QByteArrays.
These not only take less space than UTF-16 encoded QStrings, but due to the caching in the CppEditorSupport also take less time to build. This patch also fixes a number of possible encoding issues, where files and constant strings were (falsely) assumed to be UTF-8. Change-Id: Ib6f91c9a94ebed5b5dfbd4eb2998825c62c72784 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
Diffstat (limited to 'src/plugins/cpptools/cpppreprocessor.cpp')
-rw-r--r--src/plugins/cpptools/cpppreprocessor.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/plugins/cpptools/cpppreprocessor.cpp b/src/plugins/cpptools/cpppreprocessor.cpp
index 417363db3c..85ba300fc3 100644
--- a/src/plugins/cpptools/cpppreprocessor.cpp
+++ b/src/plugins/cpptools/cpppreprocessor.cpp
@@ -3,6 +3,7 @@
#include "cppmodelmanager.h"
#include <utils/hostosinfo.h>
+#include <utils/textfileformat.h>
#include <QCoreApplication>
@@ -154,14 +155,14 @@ void CppPreprocessor::resetEnvironment()
}
void CppPreprocessor::getFileContents(const QString &absoluteFilePath,
- QString *contents,
+ QByteArray *contents,
unsigned *revision) const
{
if (absoluteFilePath.isEmpty())
return;
if (m_workingCopy.contains(absoluteFilePath)) {
- const QPair<QString, unsigned> entry = m_workingCopy.get(absoluteFilePath);
+ const QPair<QByteArray, unsigned> entry = m_workingCopy.get(absoluteFilePath);
if (contents)
*contents = entry.first;
if (revision)
@@ -169,16 +170,11 @@ void CppPreprocessor::getFileContents(const QString &absoluteFilePath,
return;
}
- QFile file(absoluteFilePath);
- if (file.open(QFile::ReadOnly | QFile::Text)) {
- QTextStream stream(&file);
- stream.setCodec(Core::EditorManager::defaultTextCodec());
- if (contents)
- *contents = stream.readAll();
- if (revision)
- *revision = 0;
- file.close();
- }
+ QString errStr;
+ if (contents)
+ Utils::TextFileFormat::readFileUTF8(absoluteFilePath, contents, &errStr);
+ if (revision)
+ *revision = 0;
}
bool CppPreprocessor::checkFile(const QString &absoluteFilePath) const
@@ -370,7 +366,7 @@ void CppPreprocessor::sourceNeeded(unsigned line, const QString &fileName, Inclu
m_included.insert(absoluteFileName);
unsigned editorRevision = 0;
- QString contents;
+ QByteArray contents;
getFileContents(absoluteFileName, &contents, &editorRevision);
if (m_currentDoc) {
if (contents.isEmpty() && !QFileInfo(absoluteFileName).isAbsolute()) {