summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpppreprocessor.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2013-09-20 12:41:25 +0200
committerErik Verbruggen <erik.verbruggen@digia.com>2013-09-23 14:55:28 +0200
commit8350c4bdc2a90166db7ced2fdbba2edb6f1740fc (patch)
tree12ab69be0befa679b41b49ba4db140a41e7a2be2 /src/plugins/cpptools/cpppreprocessor.cpp
parent4eb633fd773263ceb9cb012611139b83bb730914 (diff)
downloadqt-creator-8350c4bdc2a90166db7ced2fdbba2edb6f1740fc.tar.gz
C++: fix multi-byte character handling in input.
Temporary fix: if a single byte is found with the highest bit set, then convert from utf8 to latin1. This can be removed when the lexer can handle multi-byte characters. Task-number: QTCREATORBUG-10141 Change-Id: I36a17aa18bd1b2378f12d0cecf4fd4957b38d8f2 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/cpptools/cpppreprocessor.cpp')
-rw-r--r--src/plugins/cpptools/cpppreprocessor.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cpppreprocessor.cpp b/src/plugins/cpptools/cpppreprocessor.cpp
index 85ba300fc3..48cb7fc77c 100644
--- a/src/plugins/cpptools/cpppreprocessor.cpp
+++ b/src/plugins/cpptools/cpppreprocessor.cpp
@@ -351,6 +351,18 @@ void CppPreprocessor::stopSkippingBlocks(unsigned offset)
m_currentDoc->stopSkippingBlocks(offset);
}
+// This is a temporary fix to handle non-ascii characters. This can be removed when the lexer can
+// handle multi-byte characters.
+static QByteArray convertToLatin1(const QByteArray &contents)
+{
+ const char *p = contents.constData();
+ while (char ch = *p++)
+ if (ch & 0x80)
+ return QString::fromUtf8(contents).toLatin1();
+
+ return contents;
+}
+
void CppPreprocessor::sourceNeeded(unsigned line, const QString &fileName, IncludeType type)
{
if (fileName.isEmpty())
@@ -368,6 +380,7 @@ void CppPreprocessor::sourceNeeded(unsigned line, const QString &fileName, Inclu
unsigned editorRevision = 0;
QByteArray contents;
getFileContents(absoluteFileName, &contents, &editorRevision);
+ contents = convertToLatin1(contents);
if (m_currentDoc) {
if (contents.isEmpty() && !QFileInfo(absoluteFileName).isAbsolute()) {
QString msg = QCoreApplication::translate(