forked from qt-creator/qt-creator
C++: Use Token::utf16chars{Begin,End} where appropriate
...especially in CppTools/CppEditor where the offsets are used with a QString/QTextDocument. Change-Id: Ic6d18fbc01fb9cc899a9bd2d7424cd2edae487f1 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -356,7 +356,7 @@ bool CheckSymbols::warning(AST *ast, const QString &text)
|
||||
const Token &firstToken = tokenAt(ast->firstToken());
|
||||
const Token &lastToken = tokenAt(ast->lastToken() - 1);
|
||||
|
||||
const unsigned length = lastToken.bytesEnd() - firstToken.bytesBegin();
|
||||
const unsigned length = lastToken.utf16charsEnd() - firstToken.utf16charsBegin();
|
||||
unsigned line = 1, column = 1;
|
||||
getTokenStartPosition(ast->firstToken(), &line, &column);
|
||||
|
||||
@@ -476,7 +476,7 @@ bool CheckSymbols::visit(NamespaceAST *ast)
|
||||
if (!tok.generated()) {
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(ast->identifier_token, &line, &column);
|
||||
Result use(line, column, tok.bytes(), CppHighlightingSupport::TypeUse);
|
||||
Result use(line, column, tok.utf16chars(), CppHighlightingSupport::TypeUse);
|
||||
addUse(use);
|
||||
}
|
||||
}
|
||||
@@ -726,8 +726,8 @@ void CheckSymbols::checkNamespace(NameAST *name)
|
||||
}
|
||||
}
|
||||
|
||||
const unsigned length = tokenAt(name->lastToken() - 1).bytesEnd()
|
||||
- tokenAt(name->firstToken()).bytesBegin();
|
||||
const unsigned length = tokenAt(name->lastToken() - 1).utf16charsEnd()
|
||||
- tokenAt(name->firstToken()).utf16charsBegin();
|
||||
warning(line, column, QCoreApplication::translate("CPlusPlus::CheckSymbols",
|
||||
"Expected a namespace-name"), length);
|
||||
}
|
||||
@@ -1116,7 +1116,7 @@ void CheckSymbols::addUse(unsigned tokenIndex, Kind kind)
|
||||
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(tokenIndex, &line, &column);
|
||||
const unsigned length = tok.bytes();
|
||||
const unsigned length = tok.utf16chars();
|
||||
|
||||
const Result use(line, column, length, kind);
|
||||
addUse(use);
|
||||
@@ -1153,7 +1153,7 @@ void CheckSymbols::addType(ClassOrNamespace *b, NameAST *ast)
|
||||
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(startToken, &line, &column);
|
||||
const unsigned length = tok.bytes();
|
||||
const unsigned length = tok.utf16chars();
|
||||
const Result use(line, column, length, CppHighlightingSupport::TypeUse);
|
||||
addUse(use);
|
||||
}
|
||||
@@ -1194,7 +1194,7 @@ bool CheckSymbols::maybeAddTypeOrStatic(const QList<LookupItem> &candidates, Nam
|
||||
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(startToken, &line, &column);
|
||||
const unsigned length = tok.bytes();
|
||||
const unsigned length = tok.utf16chars();
|
||||
|
||||
Kind kind = CppHighlightingSupport::TypeUse;
|
||||
if (c->enclosingEnum() != 0)
|
||||
@@ -1236,7 +1236,7 @@ bool CheckSymbols::maybeAddField(const QList<LookupItem> &candidates, NameAST *a
|
||||
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(startToken, &line, &column);
|
||||
const unsigned length = tok.bytes();
|
||||
const unsigned length = tok.utf16chars();
|
||||
|
||||
const Result use(line, column, length, CppHighlightingSupport::FieldUse);
|
||||
addUse(use);
|
||||
@@ -1320,7 +1320,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
|
||||
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(startToken, &line, &column);
|
||||
const unsigned length = tok.bytes();
|
||||
const unsigned length = tok.utf16chars();
|
||||
|
||||
// Add a diagnostic message if argument count does not match
|
||||
if (matchType == Match_TooFewArgs)
|
||||
|
||||
@@ -1012,7 +1012,7 @@ int CodeFormatter::column(int index) const
|
||||
|
||||
QStringRef CodeFormatter::currentTokenText() const
|
||||
{
|
||||
return m_currentLine.midRef(m_currentToken.bytesBegin(), m_currentToken.bytes());
|
||||
return m_currentLine.midRef(m_currentToken.utf16charsBegin(), m_currentToken.utf16chars());
|
||||
}
|
||||
|
||||
void CodeFormatter::turnInto(int newState)
|
||||
@@ -1189,10 +1189,10 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
||||
const Token &tk = currentToken();
|
||||
const bool firstToken = (tokenIndex() == 0);
|
||||
const bool lastToken = (tokenIndex() == tokenCount() - 1);
|
||||
const int tokenPosition = column(tk.bytesBegin());
|
||||
const int nextTokenPosition = lastToken ? tokenPosition + tk.bytes()
|
||||
: column(tokenAt(tokenIndex() + 1).bytesBegin());
|
||||
const int spaceOrNextTokenPosition = lastToken ? tokenPosition + tk.bytes() + 1
|
||||
const int tokenPosition = column(tk.utf16charsBegin());
|
||||
const int nextTokenPosition = lastToken ? tokenPosition + tk.utf16chars()
|
||||
: column(tokenAt(tokenIndex() + 1).utf16charsBegin());
|
||||
const int spaceOrNextTokenPosition = lastToken ? tokenPosition + tk.utf16chars() + 1
|
||||
: nextTokenPosition;
|
||||
|
||||
if (shouldClearPaddingOnEnter(newState))
|
||||
@@ -1474,7 +1474,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
|
||||
case multiline_comment_start:
|
||||
case multiline_comment_cont:
|
||||
if (!tokens.isEmpty()) {
|
||||
*indentDepth = column(tokens.at(0).bytesBegin());
|
||||
*indentDepth = column(tokens.at(0).utf16charsBegin());
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -703,8 +703,8 @@ bool CppCompletionAssistProcessor::accepts() const
|
||||
const QString &line = tc.block().text();
|
||||
const Token &idToken = tokens.at(1);
|
||||
const QStringRef &identifier =
|
||||
line.midRef(idToken.bytesBegin(),
|
||||
idToken.bytesEnd() - idToken.bytesBegin());
|
||||
line.midRef(idToken.utf16charsBegin(),
|
||||
idToken.utf16charsEnd() - idToken.utf16charsBegin());
|
||||
if (identifier == QLatin1String("include")
|
||||
|| identifier == QLatin1String("include_next")
|
||||
|| (m_languageFeatures.objCEnabled && identifier == QLatin1String("import"))) {
|
||||
@@ -838,8 +838,8 @@ int CppCompletionAssistProcessor::startOfOperator(int pos,
|
||||
if (tokens.at(0).is(T_POUND) && tokens.at(1).is(T_IDENTIFIER) && (tokens.at(2).is(T_STRING_LITERAL) ||
|
||||
tokens.at(2).is(T_ANGLE_STRING_LITERAL))) {
|
||||
const Token &directiveToken = tokens.at(1);
|
||||
QString directive = tc.block().text().mid(directiveToken.bytesBegin(),
|
||||
directiveToken.bytes());
|
||||
QString directive = tc.block().text().mid(directiveToken.utf16charsBegin(),
|
||||
directiveToken.utf16chars());
|
||||
if (directive == QLatin1String("include") ||
|
||||
directive == QLatin1String("include_next") ||
|
||||
directive == QLatin1String("import")) {
|
||||
|
||||
@@ -201,7 +201,7 @@ ChangeSet::Range CppRefactoringFile::range(unsigned tokenIndex) const
|
||||
unsigned line, column;
|
||||
cppDocument()->translationUnit()->getPosition(token.utf16charsBegin(), &line, &column);
|
||||
const int start = document()->findBlockByNumber(line - 1).position() + column - 1;
|
||||
return ChangeSet::Range(start, start + token.bytes());
|
||||
return ChangeSet::Range(start, start + token.utf16chars());
|
||||
}
|
||||
|
||||
ChangeSet::Range CppRefactoringFile::range(AST *ast) const
|
||||
@@ -241,7 +241,7 @@ void CppRefactoringFile::startAndEndOf(unsigned index, int *start, int *end) con
|
||||
Token token(tokenAt(index));
|
||||
cppDocument()->translationUnit()->getPosition(token.utf16charsBegin(), &line, &column);
|
||||
*start = document()->findBlockByNumber(line - 1).position() + column - 1;
|
||||
*end = *start + token.bytes();
|
||||
*end = *start + token.utf16chars();
|
||||
}
|
||||
|
||||
QString CppRefactoringFile::textOf(const AST *ast) const
|
||||
|
||||
@@ -83,7 +83,7 @@ QString DoxygenGenerator::generate(QTextCursor cursor)
|
||||
foreach (const Token &tk, tks) {
|
||||
if (tk.is(T_SEMICOLON) || tk.is(T_LBRACE)) {
|
||||
// No need to continue beyond this, we might already have something meaningful.
|
||||
cursor.setPosition(block.position() + tk.bytesEnd(), QTextCursor::KeepAnchor);
|
||||
cursor.setPosition(block.position() + tk.utf16charsEnd(), QTextCursor::KeepAnchor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user