Cpp{Tools,Editor}: Expect UTF-8 encoded literals

Change-Id: I9843c4163aad3fa3f1bfa33060c76328fc2dc25a
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Nikolai Kosjar
2014-05-05 11:43:24 -04:00
parent cadc4b42ba
commit bea8fc8e6a
14 changed files with 163 additions and 29 deletions

View File

@@ -530,7 +530,7 @@ protected:
void visit(const TemplateNameId *name)
{
_item = newCompletionItem(name);
_item->setText(QLatin1String(name->identifier()->chars()));
_item->setText(QString::fromUtf8(name->identifier()->chars(), name->identifier()->size()));
}
void visit(const DestructorNameId *name)
@@ -1682,9 +1682,9 @@ bool CppCompletionAssistProcessor::completeQtMethod(const QList<CPlusPlus::Looku
signature += QLatin1Char(')');
const QByteArray normalized =
QMetaObject::normalizedSignature(signature.toLatin1());
QMetaObject::normalizedSignature(signature.toUtf8());
signature = QString::fromLatin1(normalized, normalized.size());
signature = QString::fromUtf8(normalized, normalized.size());
if (!signatures.contains(signature)) {
BasicProposalItem *ci = toCompletionItem(fun);
@@ -1884,7 +1884,7 @@ bool CppCompletionAssistProcessor::completeConstructorOrFunction(const QList<CPl
QString possibleDecl = bs.mid(lineStartToken).trimmed().append(QLatin1String("();"));
Document::Ptr doc = Document::create(QLatin1String("<completion>"));
doc->setUtf8Source(possibleDecl.toLatin1());
doc->setUtf8Source(possibleDecl.toUtf8());
if (doc->parse(Document::ParseDeclaration)) {
doc->check();
if (SimpleDeclarationAST *sd = doc->translationUnit()->ast()->asSimpleDeclaration()) {

View File

@@ -95,7 +95,7 @@ static QByteArray typeId(Symbol *symbol)
} else if (symbol->asDeclaration()) {
QByteArray temp("d,");
Overview pretty;
temp.append(pretty.prettyType(symbol->type()).toLatin1());
temp.append(pretty.prettyType(symbol->type()).toUtf8());
return temp;
} else if (symbol->asArgument()) {
return QByteArray("a");

View File

@@ -86,11 +86,11 @@ protected:
continue;
if (!member->isGenerated() && (member->isDeclaration() || member->isArgument())) {
if (member->name() && member->name()->isNameId()) {
const Identifier *id = member->identifier();
const Token token = tokenAt(member->sourceLocation());
unsigned line, column;
getTokenStartPosition(member->sourceLocation(), &line, &column);
getPosition(token.utf16charsBegin(), &line, &column);
localUses[member].append(
HighlightingResult(line, column, id->size(),
HighlightingResult(line, column, token.utf16chars(),
CppHighlightingSupport::LocalUse));
}
}
@@ -101,7 +101,8 @@ protected:
bool checkLocalUse(NameAST *nameAst, unsigned firstToken)
{
if (SimpleNameAST *simpleName = nameAst->asSimpleName()) {
if (tokenAt(simpleName->identifier_token).generated())
const Token token = tokenAt(simpleName->identifier_token);
if (token.generated())
return false;
const Identifier *id = identifier(simpleName->identifier_token);
for (int i = _scopeStack.size() - 1; i != -1; --i) {
@@ -113,7 +114,7 @@ protected:
unsigned line, column;
getTokenStartPosition(simpleName->identifier_token, &line, &column);
localUses[member].append(
HighlightingResult(line, column, id->size(),
HighlightingResult(line, column, token.utf16chars(),
CppHighlightingSupport::LocalUse));
return false;
}

View File

@@ -784,7 +784,7 @@ QString nameOfFirstDeclaration(const Document::Ptr &doc)
if (CPlusPlus::Declaration *decl = s->asDeclaration()) {
if (const CPlusPlus::Name *name = decl->name()) {
if (const CPlusPlus::Identifier *identifier = name->identifier())
return QString::fromLatin1(identifier->chars(), identifier->size());
return QString::fromUtf8(identifier->chars(), identifier->size());
}
}
}

View File

@@ -429,8 +429,8 @@ void PointerDeclarationFormatter::checkAndRewrite(DeclaratorAST *declarator,
"No pointer or references in rewritten declaration");
if (DEBUG_OUTPUT) {
qDebug("==> Rewritten: \"%s\" --> \"%s\"", originalDeclaration.toLatin1().constData(),
rewrittenDeclaration.toLatin1().constData());
qDebug("==> Rewritten: \"%s\" --> \"%s\"", originalDeclaration.toUtf8().constData(),
rewrittenDeclaration.toUtf8().constData());
}
// Creating the replacement in the changeset may fail due to operations

View File

@@ -89,7 +89,7 @@ public:
// Write source to temprorary file
const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
Document::Ptr document = Document::create(filePath);
QVERIFY(writeFile(document->fileName(), sourceWithoutCursorMarker.toLatin1()));
QVERIFY(writeFile(document->fileName(), sourceWithoutCursorMarker.toUtf8()));
// Preprocess source
Environment env;
@@ -145,7 +145,7 @@ void CppToolsPlugin::test_format_pointerdeclaration_in_simpledeclarations()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
PointerDeclarationFormatterTestCase(source.toLatin1(),
PointerDeclarationFormatterTestCase(source.toUtf8(),
reformattedSource,
Document::ParseDeclaration,
PointerDeclarationFormatter::RespectCursor);
@@ -369,7 +369,7 @@ void CppToolsPlugin::test_format_pointerdeclaration_in_controlflowstatements()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
PointerDeclarationFormatterTestCase(source.toLatin1(),
PointerDeclarationFormatterTestCase(source.toUtf8(),
reformattedSource,
Document::ParseStatement,
PointerDeclarationFormatter::RespectCursor);
@@ -444,7 +444,7 @@ void CppToolsPlugin::test_format_pointerdeclaration_multiple_declarators()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
PointerDeclarationFormatterTestCase(source.toLatin1(),
PointerDeclarationFormatterTestCase(source.toUtf8(),
reformattedSource,
Document::ParseDeclaration,
PointerDeclarationFormatter::RespectCursor);
@@ -499,7 +499,7 @@ void CppToolsPlugin::test_format_pointerdeclaration_multiple_matches()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
PointerDeclarationFormatterTestCase(source.toLatin1(),
PointerDeclarationFormatterTestCase(source.toUtf8(),
reformattedSource,
Document::ParseTranlationUnit,
PointerDeclarationFormatter::IgnoreCursor);
@@ -582,7 +582,7 @@ void CppToolsPlugin::test_format_pointerdeclaration_macros()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
PointerDeclarationFormatterTestCase(source.toLatin1(),
PointerDeclarationFormatterTestCase(source.toUtf8(),
reformattedSource,
Document::ParseTranlationUnit,
PointerDeclarationFormatter::RespectCursor);