Commit f7c68f6b authored by Erik Verbruggen's avatar Erik Verbruggen

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: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent eebb1dfc
...@@ -736,7 +736,8 @@ void Snapshot::insert(Document::Ptr doc) ...@@ -736,7 +736,8 @@ void Snapshot::insert(Document::Ptr doc)
_documents.insert(doc->fileName(), doc); _documents.insert(doc->fileName(), doc);
} }
Document::Ptr Snapshot::preprocessedDocument(const QString &source, const QString &fileName) const Document::Ptr Snapshot::preprocessedDocument(const QByteArray &source,
const QString &fileName) const
{ {
Document::Ptr newDoc = Document::create(fileName); Document::Ptr newDoc = Document::create(fileName);
if (Document::Ptr thisDocument = document(fileName)) { if (Document::Ptr thisDocument = document(fileName)) {
......
...@@ -398,7 +398,7 @@ public: ...@@ -398,7 +398,7 @@ public:
Snapshot simplified(Document::Ptr doc) const; Snapshot simplified(Document::Ptr doc) const;
Document::Ptr preprocessedDocument(const QString &source, Document::Ptr preprocessedDocument(const QByteArray &source,
const QString &fileName) const; const QString &fileName) const;
Document::Ptr documentFromSource(const QByteArray &preprocessedDocument, Document::Ptr documentFromSource(const QByteArray &preprocessedDocument,
......
...@@ -41,7 +41,7 @@ FastPreprocessor::FastPreprocessor(const Snapshot &snapshot) ...@@ -41,7 +41,7 @@ FastPreprocessor::FastPreprocessor(const Snapshot &snapshot)
, _preproc(this, &_env) , _preproc(this, &_env)
{ } { }
QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QString &source) QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QByteArray &source)
{ {
std::swap(newDoc, _currentDoc); std::swap(newDoc, _currentDoc);
const QString fileName = _currentDoc->fileName(); const QString fileName = _currentDoc->fileName();
......
...@@ -54,7 +54,7 @@ class CPLUSPLUS_EXPORT FastPreprocessor: public Client ...@@ -54,7 +54,7 @@ class CPLUSPLUS_EXPORT FastPreprocessor: public Client
public: public:
FastPreprocessor(const Snapshot &snapshot); FastPreprocessor(const Snapshot &snapshot);
QByteArray run(Document::Ptr newDoc, const QString &source); QByteArray run(Document::Ptr newDoc, const QByteArray &source);
// CPlusPlus::Client // CPlusPlus::Client
virtual void sourceNeeded(unsigned line, const QString &fileName, IncludeType mode); virtual void sourceNeeded(unsigned line, const QString &fileName, IncludeType mode);
......
...@@ -271,6 +271,39 @@ TextFileFormat::ReadResult ...@@ -271,6 +271,39 @@ TextFileFormat::ReadResult
return result; return result;
} }
TextFileFormat::ReadResult TextFileFormat::readFileUTF8(const QString &fileName,
QByteArray *plainText, QString *errorString)
{
QByteArray data;
try {
Utils::FileReader reader;
if (!reader.fetch(fileName, errorString))
return TextFileFormat::ReadIOError;
data = reader.data();
} catch (const std::bad_alloc &) {
*errorString = QCoreApplication::translate("Utils::TextFileFormat", "Out of memory.");
return TextFileFormat::ReadMemoryAllocationError;
}
TextFileFormat format = TextFileFormat::detect(data);
if (!format.codec)
format.codec = QTextCodec::codecForLocale();
if (format.codec->name() == "UTF-8") {
if (format.hasUtf8Bom)
data.remove(0, 3);
*plainText = data;
return TextFileFormat::ReadSuccess;
}
QString target;
if (!format.decode(data, &target)) {
*errorString = QCoreApplication::translate("Utils::TextFileFormat", "An encoding error was encountered.");
return TextFileFormat::ReadEncodingError;
}
*plainText = target.toUtf8();
return TextFileFormat::ReadSuccess;
}
/*! /*!
\brief Write out a text file. \brief Write out a text file.
*/ */
......
...@@ -76,6 +76,8 @@ public: ...@@ -76,6 +76,8 @@ public:
static ReadResult readFile(const QString &fileName, const QTextCodec *defaultCodec, static ReadResult readFile(const QString &fileName, const QTextCodec *defaultCodec,
QString *plainText, TextFileFormat *format, QString *errorString, QString *plainText, TextFileFormat *format, QString *errorString,
QByteArray *decodingErrorSample = 0); QByteArray *decodingErrorSample = 0);
static ReadResult readFileUTF8(const QString &fileName, QByteArray *plainText,
QString *errorString);
bool writeFile(const QString &fileName, QString plainText, QString *errorString) const; bool writeFile(const QString &fileName, QString plainText, QString *errorString) const;
......
...@@ -196,7 +196,7 @@ void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileAc ...@@ -196,7 +196,7 @@ void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileAc
Snapshot snapshot = mm->snapshot(); Snapshot snapshot = mm->snapshot();
Document::Ptr document = snapshot.preprocessedDocument( Document::Ptr document = snapshot.preprocessedDocument(
editorWidget->document()->toPlainText(), filePath); editorWidget->document()->toPlainText().toUtf8(), filePath);
QVERIFY(document); QVERIFY(document);
document->parse(); document->parse();
TranslationUnit *translationUnit = document->translationUnit(); TranslationUnit *translationUnit = document->translationUnit();
......
...@@ -45,6 +45,7 @@ public: ...@@ -45,6 +45,7 @@ public:
explicit AbstractEditorSupport(CppModelManagerInterface *modelmanager); explicit AbstractEditorSupport(CppModelManagerInterface *modelmanager);
virtual ~AbstractEditorSupport(); virtual ~AbstractEditorSupport();
/// \returns the contents, encoded as UTF-8
virtual QByteArray contents() const = 0; virtual QByteArray contents() const = 0;
virtual QString fileName() const = 0; virtual QString fileName() const = 0;
......
...@@ -53,8 +53,8 @@ using namespace CppTools::Internal; ...@@ -53,8 +53,8 @@ using namespace CppTools::Internal;
using namespace CppTools; using namespace CppTools;
using namespace CPlusPlus; using namespace CPlusPlus;
static QString getSource(const QString &fileName, static QByteArray getSource(const QString &fileName,
const CppModelManagerInterface::WorkingCopy &workingCopy) const CppModelManagerInterface::WorkingCopy &workingCopy)
{ {
if (workingCopy.contains(fileName)) { if (workingCopy.contains(fileName)) {
return workingCopy.source(fileName); return workingCopy.source(fileName);
...@@ -68,7 +68,7 @@ static QString getSource(const QString &fileName, ...@@ -68,7 +68,7 @@ static QString getSource(const QString &fileName,
if (result != Utils::TextFileFormat::ReadSuccess) if (result != Utils::TextFileFormat::ReadSuccess)
qWarning() << "Could not read " << fileName << ". Error: " << error; qWarning() << "Could not read " << fileName << ". Error: " << error;
return fileContents; return fileContents.toUtf8();
} }
} }
...@@ -110,7 +110,7 @@ public: ...@@ -110,7 +110,7 @@ public:
return usages; // skip this document, it's not using symbolId. return usages; // skip this document, it's not using symbolId.
} }
Document::Ptr doc; Document::Ptr doc;
const QString unpreprocessedSource = getSource(fileName, workingCopy); const QByteArray unpreprocessedSource = getSource(fileName, workingCopy);
if (symbolDocument && fileName == symbolDocument->fileName()) { if (symbolDocument && fileName == symbolDocument->fileName()) {
doc = symbolDocument; doc = symbolDocument;
...@@ -124,7 +124,7 @@ public: ...@@ -124,7 +124,7 @@ public:
if (doc != symbolDocument) if (doc != symbolDocument)
doc->check(); doc->check();
FindUsages process(unpreprocessedSource.toUtf8(), doc, snapshot); FindUsages process(unpreprocessedSource, doc, snapshot);
process(symbol); process(symbol);
usages = process.usages(); usages = process.usages();
...@@ -439,7 +439,7 @@ bool CppFindReferences::findSymbol(CppFindReferencesParameters *parameters, ...@@ -439,7 +439,7 @@ bool CppFindReferences::findSymbol(CppFindReferencesParameters *parameters,
Document::Ptr newSymbolDocument = snapshot.document(symbolFile); Document::Ptr newSymbolDocument = snapshot.document(symbolFile);
// document is not parsed and has no bindings yet, do it // document is not parsed and has no bindings yet, do it
QString source = getSource(newSymbolDocument->fileName(), _modelManager->workingCopy()); QByteArray source = getSource(newSymbolDocument->fileName(), _modelManager->workingCopy());
Document::Ptr doc = Document::Ptr doc =
snapshot.preprocessedDocument(source, newSymbolDocument->fileName()); snapshot.preprocessedDocument(source, newSymbolDocument->fileName());
doc->check(); doc->check();
...@@ -541,7 +541,7 @@ public: ...@@ -541,7 +541,7 @@ public:
{ {
QList<Usage> usages; QList<Usage> usages;
Document::Ptr doc = snapshot.document(fileName); Document::Ptr doc = snapshot.document(fileName);
QString source; QByteArray source;
restart_search: restart_search:
if (future->isPaused()) if (future->isPaused())
...@@ -566,8 +566,8 @@ restart_search: ...@@ -566,8 +566,8 @@ restart_search:
if (macro.name() == useMacro.name()) { if (macro.name() == useMacro.name()) {
unsigned lineStart; unsigned lineStart;
const QString &lineSource = matchingLine(use.begin(), source, &lineStart); const QByteArray &lineSource = matchingLine(use.begin(), source, &lineStart);
usages.append(Usage(fileName, lineSource, use.beginLine(), usages.append(Usage(fileName, QString::fromUtf8(lineSource), use.beginLine(),
use.begin() - lineStart, useMacro.name().length())); use.begin() - lineStart, useMacro.name().length()));
} }
} }
...@@ -578,18 +578,18 @@ restart_search: ...@@ -578,18 +578,18 @@ restart_search:
return usages; return usages;
} }
static QString matchingLine(unsigned position, const QString &source, static QByteArray matchingLine(unsigned position, const QByteArray &source,
unsigned *lineStart = 0) unsigned *lineStart = 0)
{ {
int lineBegin = source.lastIndexOf(QLatin1Char('\n'), position) + 1; int lineBegin = source.lastIndexOf('\n', position) + 1;
int lineEnd = source.indexOf(QLatin1Char('\n'), position); int lineEnd = source.indexOf('\n', position);
if (lineEnd == -1) if (lineEnd == -1)
lineEnd = source.length(); lineEnd = source.length();
if (lineStart) if (lineStart)
*lineStart = lineBegin; *lineStart = lineBegin;
const QString matchingLine = source.mid(lineBegin, lineEnd - lineBegin); const QByteArray matchingLine = source.mid(lineBegin, lineEnd - lineBegin);
return matchingLine; return matchingLine;
} }
}; };
...@@ -652,10 +652,11 @@ void CppFindReferences::findMacroUses(const Macro &macro, const QString &replace ...@@ -652,10 +652,11 @@ void CppFindReferences::findMacroUses(const Macro &macro, const QString &replace
// add the macro definition itself // add the macro definition itself
{ {
const QString &source = getSource(macro.fileName(), workingCopy); const QByteArray &source = getSource(macro.fileName(), workingCopy);
unsigned lineStart; unsigned lineStart;
const QString line = FindMacroUsesInFile::matchingLine(macro.offset(), source, &lineStart); const QByteArray line = FindMacroUsesInFile::matchingLine(macro.offset(), source,
search->addResult(macro.fileName(), macro.line(), line, &lineStart);
search->addResult(macro.fileName(), macro.line(), QString::fromUtf8(line),
macro.offset() - lineStart, macro.name().length()); macro.offset() - lineStart, macro.name().length());
} }
......
...@@ -541,13 +541,13 @@ CppModelManager::WorkingCopy CppModelManager::buildWorkingCopyList() ...@@ -541,13 +541,13 @@ CppModelManager::WorkingCopy CppModelManager::buildWorkingCopyList()
QSetIterator<AbstractEditorSupport *> it(m_extraEditorSupports); QSetIterator<AbstractEditorSupport *> it(m_extraEditorSupports);
while (it.hasNext()) { while (it.hasNext()) {
AbstractEditorSupport *es = it.next(); AbstractEditorSupport *es = it.next();
workingCopy.insert(es->fileName(), QString::fromUtf8(es->contents())); workingCopy.insert(es->fileName(), es->contents());
} }
// Add the project configuration file // Add the project configuration file
QByteArray conf(pp_configuration); QByteArray conf = QByteArray::fromRawData(pp_configuration, qstrlen(pp_configuration));
conf += definedMacros(); conf += definedMacros();
workingCopy.insert(configurationFileName(), QString::fromLocal8Bit(conf)); workingCopy.insert(configurationFileName(), conf);
return workingCopy; return workingCopy;
} }
......
...@@ -673,7 +673,7 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles() ...@@ -673,7 +673,7 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
QCOMPARE(workingCopy.size(), 2); // mm->configurationFileName() and "ui_*.h" QCOMPARE(workingCopy.size(), 2); // mm->configurationFileName() and "ui_*.h"
QStringList fileNamesInWorkinCopy; QStringList fileNamesInWorkinCopy;
QHashIterator<QString, QPair<QString, unsigned> > it = workingCopy.iterator(); QHashIterator<QString, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
fileNamesInWorkinCopy << QFileInfo(it.key()).fileName(); fileNamesInWorkinCopy << QFileInfo(it.key()).fileName();
......
...@@ -176,29 +176,38 @@ public: ...@@ -176,29 +176,38 @@ public:
QByteArray m_defines; QByteArray m_defines;
}; };
/// The working-copy stores all files that are stored on disk in their current state.
///
/// So, currently the working copy holds:
/// - unsaved content of editors
/// - uic-ed UI files (through \c AbstractEditorSupport)
/// - the preprocessor configuration
///
/// Contents are keyed on filename, and hold the revision in the editor and the editor's
/// contents encoded as UTF-8.
class CPPTOOLS_EXPORT WorkingCopy class CPPTOOLS_EXPORT WorkingCopy
{ {
public: public:
void insert(const QString &fileName, const QString &source, unsigned revision = 0) void insert(const QString &fileName, const QByteArray &source, unsigned revision = 0)
{ _elements.insert(fileName, qMakePair(source, revision)); } { _elements.insert(fileName, qMakePair(source, revision)); }
bool contains(const QString &fileName) const bool contains(const QString &fileName) const
{ return _elements.contains(fileName); } { return _elements.contains(fileName); }
QString source(const QString &fileName) const QByteArray source(const QString &fileName) const
{ return _elements.value(fileName).first; } { return _elements.value(fileName).first; }
QPair<QString, unsigned> get(const QString &fileName) const QPair<QByteArray, unsigned> get(const QString &fileName) const
{ return _elements.value(fileName); } { return _elements.value(fileName); }
QHashIterator<QString, QPair<QString, unsigned> > iterator() const QHashIterator<QString, QPair<QByteArray, unsigned> > iterator() const
{ return QHashIterator<QString, QPair<QString, unsigned> >(_elements); } { return QHashIterator<QString, QPair<QByteArray, unsigned> >(_elements); }
int size() const int size() const
{ return _elements.size(); } { return _elements.size(); }
private: private:
typedef QHash<QString, QPair<QString, unsigned> > Table; typedef QHash<QString, QPair<QByteArray, unsigned> > Table;
Table _elements; Table _elements;
}; };
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/textfileformat.h>
#include <QCoreApplication> #include <QCoreApplication>
...@@ -154,14 +155,14 @@ void CppPreprocessor::resetEnvironment() ...@@ -154,14 +155,14 @@ void CppPreprocessor::resetEnvironment()
} }
void CppPreprocessor::getFileContents(const QString &absoluteFilePath, void CppPreprocessor::getFileContents(const QString &absoluteFilePath,
QString *contents, QByteArray *contents,
unsigned *revision) const unsigned *revision) const
{ {
if (absoluteFilePath.isEmpty()) if (absoluteFilePath.isEmpty())
return; return;
if (m_workingCopy.contains(absoluteFilePath)) { 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) if (contents)
*contents = entry.first; *contents = entry.first;
if (revision) if (revision)
...@@ -169,16 +170,11 @@ void CppPreprocessor::getFileContents(const QString &absoluteFilePath, ...@@ -169,16 +170,11 @@ void CppPreprocessor::getFileContents(const QString &absoluteFilePath,
return; return;
} }
QFile file(absoluteFilePath); QString errStr;
if (file.open(QFile::ReadOnly | QFile::Text)) { if (contents)
QTextStream stream(&file); Utils::TextFileFormat::readFileUTF8(absoluteFilePath, contents, &errStr);
stream.setCodec(Core::EditorManager::defaultTextCodec()); if (revision)
if (contents) *revision = 0;
*contents = stream.readAll();
if (revision)
*revision = 0;
file.close();
}
} }
bool CppPreprocessor::checkFile(const QString &absoluteFilePath) const bool CppPreprocessor::checkFile(const QString &absoluteFilePath) const
...@@ -370,7 +366,7 @@ void CppPreprocessor::sourceNeeded(unsigned line, const QString &fileName, Inclu ...@@ -370,7 +366,7 @@ void CppPreprocessor::sourceNeeded(unsigned line, const QString &fileName, Inclu
m_included.insert(absoluteFileName); m_included.insert(absoluteFileName);
unsigned editorRevision = 0; unsigned editorRevision = 0;
QString contents; QByteArray contents;
getFileContents(absoluteFileName, &contents, &editorRevision); getFileContents(absoluteFileName, &contents, &editorRevision);
if (m_currentDoc) { if (m_currentDoc) {
if (contents.isEmpty() && !QFileInfo(absoluteFileName).isAbsolute()) { if (contents.isEmpty() && !QFileInfo(absoluteFileName).isAbsolute()) {
......
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
protected: protected:
CPlusPlus::Document::Ptr switchDocument(CPlusPlus::Document::Ptr doc); CPlusPlus::Document::Ptr switchDocument(CPlusPlus::Document::Ptr doc);
void getFileContents(const QString &absoluteFilePath, QString *contents, unsigned *revision) const; void getFileContents(const QString &absoluteFilePath, QByteArray *contents, unsigned *revision) const;
bool checkFile(const QString &absoluteFilePath) const; bool checkFile(const QString &absoluteFilePath) const;
QString resolveFile(const QString &fileName, IncludeType type); QString resolveFile(const QString &fileName, IncludeType type);
QString resolveFile_helper(const QString &fileName, IncludeType type); QString resolveFile_helper(const QString &fileName, IncludeType type);
......
...@@ -109,7 +109,7 @@ CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const QString &fi ...@@ -109,7 +109,7 @@ CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const QString &fi
{ {
QTextDocument *document = 0; QTextDocument *document = 0;
if (data()->m_workingCopy.contains(fileName)) if (data()->m_workingCopy.contains(fileName))
document = new QTextDocument(data()->m_workingCopy.source(fileName)); document = new QTextDocument(QString::fromUtf8(data()->m_workingCopy.source(fileName)));
CppRefactoringFilePtr result(new CppRefactoringFile(document, fileName)); CppRefactoringFilePtr result(new CppRefactoringFile(document, fileName));
result->m_data = m_data; result->m_data = m_data;
...@@ -144,7 +144,7 @@ Document::Ptr CppRefactoringFile::cppDocument() const ...@@ -144,7 +144,7 @@ Document::Ptr CppRefactoringFile::cppDocument() const
{ {
if (!m_cppDocument || !m_cppDocument->translationUnit() || if (!m_cppDocument || !m_cppDocument->translationUnit() ||
!m_cppDocument->translationUnit()->ast()) { !m_cppDocument->translationUnit()->ast()) {
const QString source = document()->toPlainText(); const QByteArray source = document()->toPlainText().toUtf8();
const QString name = fileName(); const QString name = fileName();
const Snapshot &snapshot = data()->m_snapshot; const Snapshot &snapshot = data()->m_snapshot;
......
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
{ {
const CPlusPlus::Snapshot snapshot; const CPlusPlus::Snapshot snapshot;
const QString fileName; const QString fileName;
const QString code; const QByteArray code;
const int line; const int line;
const int column; const int column;
const unsigned revision; const unsigned revision;
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
Source(const CPlusPlus::Snapshot &snapshot, Source(const CPlusPlus::Snapshot &snapshot,
const QString &fileName, const QString &fileName,
const QString &code, const QByteArray &code,
int line, int column, int line, int column,
unsigned revision, unsigned revision,
bool force) bool force)
......
...@@ -166,12 +166,12 @@ QString CppEditorSupport::fileName() const ...@@ -166,12 +166,12 @@ QString CppEditorSupport::fileName() const
return m_textEditor->document()->filePath(); return m_textEditor->document()->filePath();
} }
QString CppEditorSupport::contents() const QByteArray CppEditorSupport::contents() const
{ {
const int editorRev = editorRevision(); const int editorRev = editorRevision();
if (m_cachedContentsEditorRevision != editorRev && !m_fileIsBeingReloaded) { if (m_cachedContentsEditorRevision != editorRev && !m_fileIsBeingReloaded) {
m_cachedContentsEditorRevision = editorRev; m_cachedContentsEditorRevision = editorRev;
m_cachedContents = m_textEditor->textDocument()->contents(); m_cachedContents = m_textEditor->textDocument()->contents().toUtf8();
} }
return m_cachedContents; return m_cachedContents;
...@@ -430,7 +430,7 @@ SemanticInfo::Source CppEditorSupport::currentSource(bool force) ...@@ -430,7 +430,7 @@ SemanticInfo::Source CppEditorSupport::currentSource(bool force)
const Snapshot snapshot = m_modelManager->snapshot(); const Snapshot snapshot = m_modelManager->snapshot();
QString code; QByteArray code;
if (force || m_lastSemanticInfo.revision != editorRevision()) if (force || m_lastSemanticInfo.revision != editorRevision())
code = contents(); // get the source code only when needed. code = contents(); // get the source code only when needed.
......
...@@ -96,7 +96,7 @@ public: ...@@ -96,7 +96,7 @@ public:
QString fileName() const; QString fileName() const;
QString contents() const; QByteArray contents() const;
unsigned editorRevision() const; unsigned editorRevision() const;
void setExtraDiagnostics(const QString &key, void setExtraDiagnostics(const QString &key,
...@@ -173,7 +173,7 @@ private: ...@@ -173,7 +173,7 @@ private:
QFuture<void> m_documentParser; QFuture<void> m_documentParser;
// content caching // content caching
mutable QString m_cachedContents; mutable QByteArray m_cachedContents;
mutable int m_cachedContentsEditorRevision; mutable int m_cachedContentsEditorRevision;
bool m_fileIsBeingReloaded; bool m_fileIsBeingReloaded;
......
...@@ -2702,13 +2702,13 @@ static CPlusPlus::Document::Ptr getParsedDocument(const QString &fileName, ...@@ -2702,13 +2702,13 @@ static CPlusPlus::Document::Ptr getParsedDocument(const QString &fileName,
const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy, const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy,
const CPlusPlus::Snapshot &snapshot) const CPlusPlus::Snapshot &snapshot)
{ {
QString src; QByteArray src;
if (workingCopy.contains(fileName)) { if (workingCopy.contains(fileName)) {
src = workingCopy.source(fileName); src = workingCopy.source(fileName);
} else { } else {
FileReader reader; FileReader reader;
if (reader.fetch(fileName)) // ### FIXME error reporting if (reader.fetch(fileName)) // ### FIXME error reporting
src = QString::fromLocal8Bit(reader.data()); // ### FIXME encoding src = QString::fromLocal8Bit(reader.data()).toUtf8();
} }
CPlusPlus::Document::Ptr doc = snapshot.preprocessedDocument(src, fileName); CPlusPlus::Document::Ptr doc = snapshot.preprocessedDocument(src, fileName);
......
...@@ -493,13 +493,13 @@ static Document::Ptr getParsedDocument(const QString &fileName, ...@@ -493,13 +493,13 @@ static Document::Ptr getParsedDocument(const QString &fileName,
CppTools::CppModelManagerInterface::WorkingCopy &workingCopy, CppTools::CppModelManagerInterface::WorkingCopy &workingCopy,
Snapshot &snapshot) Snapshot &snapshot)
{ {
QString src; QByteArray src;
if (workingCopy.contains(fileName)) { if (workingCopy.contains(fileName)) {
src = workingCopy.source(fileName); src = workingCopy.source(fileName);
} else { } else {
Utils::FileReader reader; Utils::FileReader reader;
if (reader.fetch(fileName)) // ### FIXME error reporting if (reader.fetch(fileName)) // ### FIXME error reporting
src = QString::fromLocal8Bit(reader.data()); // ### FIXME encoding src = QString::fromLocal8Bit(reader.data()).toUtf8();
} }
Document::Ptr doc = snapshot.preprocessedDocument(src, fileName); Document::Ptr doc = snapshot.preprocessedDocument(src, fileName);
...@@ -547,7 +547,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName, ...@@ -547,7 +547,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
} else { } else {
const CppTools::CppModelManagerInterface::WorkingCopy workingCopy = const CppTools::CppModelManagerInterface::WorkingCopy workingCopy =
CppTools::CppModelManagerInterface::instance()->workingCopy(); CppTools::CppModelManagerInterface::instance()->workingCopy();
QHashIterator<QString, QPair<QString, unsigned> > it = workingCopy.iterator(); QHashIterator<QString, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
const QString fileName = it.key(); const QString fileName = it.key();
......