Commit 126e6913 authored by Nikolai Kosjar's avatar Nikolai Kosjar

C++: Clarify units of a Token

This will avoid confusion when later more length and indices methods are
added.

In Token:
    length() --> bytes()
    begin() --> bytesBegin()
    end() --> bytesEnd()

Change-Id: I244c69b022e239ee762b4114559e707f93ff344f
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent ba76baa6
......@@ -86,7 +86,7 @@ void ASTVisitor::getTokenPosition(unsigned index,
{ translationUnit()->getTokenPosition(index, line, column, fileName); }
void ASTVisitor::getTokenStartPosition(unsigned index, unsigned *line, unsigned *column) const
{ getPosition(tokenAt(index).begin(), line, column); }
{ getPosition(tokenAt(index).bytesBegin(), line, column); }
void ASTVisitor::getTokenEndPosition(unsigned index, unsigned *line, unsigned *column) const
{ getPosition(tokenAt(index).end(), line, column); }
{ getPosition(tokenAt(index).bytesEnd(), line, column); }
This diff is collapsed.
......@@ -108,7 +108,7 @@ void Lexer::scan(Token *tok)
{
tok->reset();
scan_helper(tok);
tok->f.length = _currentChar - _tokenStart;
tok->f.bytes = _currentChar - _tokenStart;
}
void Lexer::scan_helper(Token *tok)
......@@ -141,7 +141,7 @@ void Lexer::scan_helper(Token *tok)
tok->lineno = _currentLine;
_tokenStart = _currentChar;
tok->offset = _currentChar - _firstChar;
tok->byteOffset = _currentChar - _firstChar;
if (_yychar) {
s._newlineExpected = false;
......
......@@ -166,7 +166,7 @@ void Symbol::setSourceLocation(unsigned sourceLocation, TranslationUnit *transla
if (translationUnit) {
const Token &tk = translationUnit->tokenAt(sourceLocation);
_isGenerated = tk.generated();
translationUnit->getPosition(tk.begin(), &_line, &_column, &_fileId);
translationUnit->getPosition(tk.bytesBegin(), &_line, &_column, &_fileId);
} else {
_isGenerated = false;
_line = 0;
......
......@@ -84,7 +84,7 @@ const char *token_names[] = {
void Token::reset()
{
flags = 0;
offset = 0;
byteOffset = 0;
ptr = 0;
}
......
......@@ -285,7 +285,7 @@ enum Kind {
class CPLUSPLUS_EXPORT Token
{
public:
Token() : flags(0), offset(0), ptr(0) {}
Token() : flags(0), byteOffset(0), ptr(0) {}
inline bool is(unsigned k) const { return f.kind == k; }
inline bool isNot(unsigned k) const { return f.kind != k; }
......@@ -298,13 +298,13 @@ public:
inline bool joined() const { return f.joined; }
inline bool expanded() const { return f.expanded; }
inline bool generated() const { return f.generated; }
inline unsigned length() const { return f.length; }
inline unsigned bytes() const { return f.bytes; }
inline unsigned begin() const
{ return offset; }
inline unsigned bytesBegin() const
{ return byteOffset; }
inline unsigned end() const
{ return offset + f.length; }
inline unsigned bytesEnd() const
{ return byteOffset + f.bytes; }
inline bool isLiteral() const
{ return f.kind >= T_FIRST_LITERAL && f.kind <= T_LAST_LITERAL; }
......@@ -333,15 +333,15 @@ public:
public:
struct Flags {
// The token kind.
unsigned kind : 8;
unsigned kind : 8;
// The token starts a new line.
unsigned newline : 1;
// The token is preceded by whitespace(s).
unsigned whitespace : 1;
unsigned newline : 1;
// The token is preceeded by whitespace(s).
unsigned whitespace : 1;
// The token is joined with the previous one.
unsigned joined : 1;
unsigned joined : 1;
// The token originates from a macro expansion.
unsigned expanded : 1;
unsigned expanded : 1;
// The token originates from a macro expansion and does not correspond to an
// argument that went through substitution. Notice the example:
//
......@@ -351,18 +351,18 @@ public:
// After preprocessing we would expect the following tokens: 1 + 2;
// Tokens '1', '+', '2', and ';' are all expanded. However only tokens '+' and ';'
// are generated.
unsigned generated : 1;
unsigned generated : 1;
// Unused...
unsigned pad : 3;
// The token length.
unsigned length : 16;
unsigned pad : 3;
// The token length in bytes.
unsigned bytes : 16;
};
union {
unsigned flags;
Flags f;
};
unsigned offset;
unsigned byteOffset;
union {
void *ptr;
......
......@@ -164,7 +164,7 @@ void TranslationUnit::tokenize()
_Lrecognize:
if (tk.is(T_POUND) && tk.newline()) {
unsigned offset = tk.begin();
unsigned offset = tk.byteOffset;
lex(&tk);
if (! tk.newline() && tk.is(T_IDENTIFIER) && tk.identifier == expansionId) {
......@@ -264,7 +264,7 @@ void TranslationUnit::tokenize()
currentExpanded = true;
const std::pair<unsigned, unsigned> &p = lineColumn[lineColumnIdx];
if (p.first)
_expandedLineColumn.insert(std::make_pair(tk.begin(), p));
_expandedLineColumn.insert(std::make_pair(tk.bytesBegin(), p));
else
currentGenerated = true;
......@@ -382,17 +382,17 @@ void TranslationUnit::getTokenPosition(unsigned index,
unsigned *line,
unsigned *column,
const StringLiteral **fileName) const
{ return getPosition(tokenAt(index).begin(), line, column, fileName); }
{ return getPosition(tokenAt(index).bytesBegin(), line, column, fileName); }
void TranslationUnit::getTokenStartPosition(unsigned index, unsigned *line,
unsigned *column,
const StringLiteral **fileName) const
{ return getPosition(tokenAt(index).begin(), line, column, fileName); }
{ return getPosition(tokenAt(index).bytesBegin(), line, column, fileName); }
void TranslationUnit::getTokenEndPosition(unsigned index, unsigned *line,
unsigned *column,
const StringLiteral **fileName) const
{ return getPosition(tokenAt(index).end(), line, column, fileName); }
{ return getPosition(tokenAt(index).bytesEnd(), line, column, fileName); }
void TranslationUnit::getPosition(unsigned tokenOffset,
unsigned *line,
......@@ -508,7 +508,7 @@ void TranslationUnit::fatal(unsigned index, const char *format, ...)
unsigned TranslationUnit::findPreviousLineOffset(unsigned tokenIndex) const
{
unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(tokenIndex).begin())];
unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(tokenIndex).bytesBegin())];
return lineOffset;
}
......@@ -521,21 +521,21 @@ bool TranslationUnit::maybeSplitGreaterGreaterToken(unsigned tokenIndex)
return false;
tok.f.kind = T_GREATER;
tok.f.length = 1;
tok.f.bytes = 1;
Token newGreater;
newGreater.f.kind = T_GREATER;
newGreater.f.expanded = tok.expanded();
newGreater.f.generated = tok.generated();
newGreater.f.length = 1;
newGreater.offset = tok.offset + 1;
newGreater.f.bytes = 1;
newGreater.byteOffset = tok.byteOffset + 1;
_tokens->insert(_tokens->begin() + tokenIndex + 1, newGreater);
TokenLineColumn::const_iterator it = _expandedLineColumn.find(tok.begin());
TokenLineColumn::const_iterator it = _expandedLineColumn.find(tok.bytesBegin());
if (it != _expandedLineColumn.end()) {
const std::pair<unsigned, unsigned> newPosition(it->second.first, it->second.second + 1);
_expandedLineColumn.insert(std::make_pair(newGreater.begin(), newPosition));
_expandedLineColumn.insert(std::make_pair(newGreater.bytesBegin(), newPosition));
}
return true;
......@@ -551,7 +551,7 @@ void TranslationUnit::releaseTokensAndComments()
void TranslationUnit::showErrorLine(unsigned index, unsigned column, FILE *out)
{
unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(index).begin())];
unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(index).bytesBegin())];
for (const char *cp = _firstSourceChar + lineOffset + 1; *cp && *cp != '\n'; ++cp) {
fputc(*cp, out);
}
......
......@@ -87,7 +87,7 @@ const Token &BackwardsScanner::fetchToken(int tokenIndex)
QList<Token> adaptedTokens;
for (int i = 0; i < _tokens.size(); ++i) {
Token t = _tokens.at(i);
t.offset += + blockText.length() + 1;
t.byteOffset += + blockText.length() + 1;
adaptedTokens.append(t);
}
......@@ -112,19 +112,19 @@ QString BackwardsScanner::text() const
QString BackwardsScanner::mid(int index) const
{
const Token &firstToken = _tokens.at(index + _offset);
return _text.mid(firstToken.begin());
return _text.mid(firstToken.bytesBegin());
}
QString BackwardsScanner::text(int index) const
{
const Token &firstToken = _tokens.at(index + _offset);
return _text.mid(firstToken.begin(), firstToken.length());
return _text.mid(firstToken.bytesBegin(), firstToken.bytes());
}
QStringRef BackwardsScanner::textRef(int index) const
{
const Token &firstToken = _tokens.at(index + _offset);
return _text.midRef(firstToken.begin(), firstToken.length());
return _text.midRef(firstToken.bytesBegin(), firstToken.bytes());
}
int BackwardsScanner::size() const
......@@ -247,8 +247,8 @@ QString BackwardsScanner::indentationString(int index) const
{
const Token tokenAfterNewline = operator[](startOfLine(index + 1));
const int newlinePos = qMax(0, _text.lastIndexOf(QLatin1Char('\n'),
tokenAfterNewline.begin()));
return _text.mid(newlinePos, tokenAfterNewline.begin() - newlinePos);
tokenAfterNewline.bytesBegin()));
return _text.mid(newlinePos, tokenAfterNewline.bytesBegin() - newlinePos);
}
......
......@@ -266,7 +266,7 @@ int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor) const
if (tk.is(T_EOF_SYMBOL)) {
break;
} else if (tk.is(T_LPAREN)) {
return scanner.startPosition() + tk.begin();
return scanner.startPosition() + tk.bytesBegin();
} else if (tk.is(T_RPAREN)) {
int matchingBrace = scanner.startOfMatchingBrace(index);
......
......@@ -140,7 +140,7 @@ void FindUsages::reportResult(unsigned tokenIndex, const QList<LookupItem> &cand
QString FindUsages::matchingLine(const Token &tk) const
{
const char *beg = _source.constData();
const char *cp = beg + tk.begin();
const char *cp = beg + tk.bytesBegin();
for (; cp != beg - 1; --cp) {
if (*cp == '\n')
break;
......@@ -178,7 +178,7 @@ void FindUsages::reportResult(unsigned tokenIndex)
if (col)
--col; // adjust the column position.
const int len = tk.length();
const int len = tk.bytes();
const Usage u(_doc->fileName(), lineText, line, col, len);
_usages.append(u);
......@@ -259,8 +259,8 @@ bool FindUsages::checkCandidates(const QList<LookupItem> &candidates) const
void FindUsages::checkExpression(unsigned startToken, unsigned endToken, Scope *scope)
{
const unsigned begin = tokenAt(startToken).begin();
const unsigned end = tokenAt(endToken).end();
const unsigned begin = tokenAt(startToken).bytesBegin();
const unsigned end = tokenAt(endToken).bytesEnd();
const QByteArray expression = _source.mid(begin, end - begin);
// qDebug() << "*** check expression:" << expression;
......
......@@ -55,8 +55,8 @@ int ByteArrayRef::count(char ch) const
void Internal::PPToken::squeezeSource()
{
if (hasSource()) {
m_src = m_src.mid(offset, f.length);
m_src = m_src.mid(byteOffset, f.bytes);
m_src.squeeze();
offset = 0;
byteOffset = 0;
}
}
......@@ -129,10 +129,10 @@ public:
{ return m_src.constData(); }
const char *tokenStart() const
{ return bufferStart() + offset; }
{ return bufferStart() + byteOffset; }
ByteArrayRef asByteArrayRef() const
{ return ByteArrayRef(&m_src, offset, length()); }
{ return ByteArrayRef(&m_src, byteOffset, bytes()); }
private:
QByteArray m_src;
......
......@@ -89,7 +89,7 @@ QList<Token> SimpleLexer::operator()(const QString &text, int state)
break;
}
QStringRef spell = text.midRef(tk.begin(), tk.length());
QStringRef spell = text.midRef(tk.bytesBegin(), tk.bytes());
lex.setScanAngleStringLiteralTokens(false);
if (tk.newline() && tk.is(T_POUND))
......@@ -116,7 +116,7 @@ int SimpleLexer::tokenAt(const QList<Token> &tokens, unsigned offset)
{
for (int index = tokens.size() - 1; index >= 0; --index) {
const Token &tk = tokens.at(index);
if (tk.begin() <= offset && tk.end() >= offset)
if (tk.bytesBegin() <= offset && tk.bytesEnd() >= offset)
return index;
}
......@@ -144,7 +144,7 @@ int SimpleLexer::tokenBefore(const QList<Token> &tokens, unsigned offset)
{
for (int index = tokens.size() - 1; index >= 0; --index) {
const Token &tk = tokens.at(index);
if (tk.begin() <= offset)
if (tk.bytesBegin() <= offset)
return index;
}
......
This diff is collapsed.
......@@ -225,8 +225,10 @@ protected:
// go through comments backwards to find the annotation closest to the call
for (unsigned i = _doc->translationUnit()->commentCount(); i-- > 0; ) {
const Token commentToken = _doc->translationUnit()->commentAt(i);
if (commentToken.begin() >= end.begin() || commentToken.end() <= begin.begin())
if (commentToken.bytesBegin() >= end.bytesBegin()
|| commentToken.bytesEnd() <= begin.bytesBegin()) {
continue;
}
const QString comment = stringOf(commentToken);
if (uriAnnotation.indexIn(comment) != -1) {
packageName = uriAnnotation.cap(1);
......@@ -274,7 +276,8 @@ protected:
// and the expression
const Token begin = translationUnit()->tokenAt(typeId->firstToken());
const Token last = translationUnit()->tokenAt(typeId->lastToken() - 1);
exportedType.typeExpression = QString::fromUtf8(_doc->utf8Source().mid(begin.begin(), last.end() - begin.begin()));
exportedType.typeExpression = QString::fromUtf8(
_doc->utf8Source().mid(begin.bytesBegin(), last.bytesEnd() - begin.bytesBegin()));
_exportedTypes += exportedType;
......@@ -401,12 +404,14 @@ private:
{
const Token firstToken = translationUnit()->tokenAt(first);
const Token lastToken = translationUnit()->tokenAt(last);
return QString::fromUtf8(_doc->utf8Source().mid(firstToken.begin(), lastToken.end() - firstToken.begin()));
return QString::fromUtf8(
_doc->utf8Source().mid(firstToken.bytesBegin(),
lastToken.bytesEnd() - firstToken.bytesBegin()));
}
QString stringOf(const Token &token)
{
return QString::fromUtf8(_doc->utf8Source().mid(token.begin(), token.length()));
return QString::fromUtf8(_doc->utf8Source().mid(token.bytesBegin(), token.bytes()));
}
ExpressionAST *skipStringCall(ExpressionAST *exp)
......
......@@ -806,8 +806,8 @@ int ClangCompletionAssistProcessor::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 CPlusPlus::Token &directiveToken = tokens.at(1);
QString directive = tc.block().text().mid(directiveToken.begin(),
directiveToken.length());
QString directive = tc.block().text().mid(directiveToken.bytesBegin(),
directiveToken.bytes());
if (directive == QLatin1String("include") ||
directive == QLatin1String("include_next") ||
directive == QLatin1String("import")) {
......@@ -885,7 +885,8 @@ bool ClangCompletionAssistProcessor::accepts() const
const QString &line = tc.block().text();
const CPlusPlus::Token &idToken = tokens.at(1);
const QStringRef &identifier =
line.midRef(idToken.begin(), idToken.end() - idToken.begin());
line.midRef(idToken.bytesBegin(),
idToken.bytesEnd() - idToken.bytesBegin());
if (identifier == QLatin1String("include")
|| identifier == QLatin1String("include_next")
|| (m_interface->objcEnabled() && identifier == QLatin1String("import"))) {
......
......@@ -72,7 +72,7 @@ bool CppAutoCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor
if (token.isStringLiteral() || token.isCharLiteral()) {
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (pos <= token.end())
if (pos <= token.bytesEnd())
return false;
}
......@@ -115,10 +115,10 @@ bool CppAutoCompleter::isInCommentHelper(const QTextCursor &cursor, Token *retTo
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (tokens.isEmpty() || pos < tokens.first().begin())
if (tokens.isEmpty() || pos < tokens.first().bytesBegin())
return prevState > 0;
if (pos >= tokens.last().end()) {
if (pos >= tokens.last().bytesEnd()) {
const Token tk = tokens.last();
if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))
return true;
......@@ -137,7 +137,7 @@ const Token CppAutoCompleter::tokenAtPosition(const QList<Token> &tokens, const
{
for (int i = tokens.size() - 1; i >= 0; --i) {
const Token tk = tokens.at(i);
if (pos >= tk.begin() && pos < tk.end())
if (pos >= tk.bytesBegin() && pos < tk.bytesEnd())
return tk;
}
return Token();
......
......@@ -821,8 +821,8 @@ public:
void clear();
enum Columns { SpelledColumn, KindColumn, IndexColumn, OffsetColumn, LineColumnNumberColumn,
LengthColumn, GeneratedColumn, ExpandedColumn, WhiteSpaceColumn, NewlineColumn,
ColumnCount };
LengthInBytesColumn, GeneratedColumn, ExpandedColumn, WhiteSpaceColumn,
NewlineColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
......@@ -852,7 +852,7 @@ void TokensModel::configure(CPlusPlus::TranslationUnit *translationUnit)
for (int i = 0, total = translationUnit->tokenCount(); i < total; ++i) {
TokenInfo info;
info.token = translationUnit->tokenAt(i);
translationUnit->getPosition(info.token.begin(), &info.line, &info.column);
translationUnit->getPosition(info.token.bytesBegin(), &info.line, &info.column);
m_tokenInfos.append(info);
}
emit layoutChanged();
......@@ -888,12 +888,12 @@ QVariant TokensModel::data(const QModelIndex &index, int role) const
else if (column == IndexColumn)
return index.row();
else if (column == OffsetColumn)
return token.begin();
return token.bytesBegin();
else if (column == LineColumnNumberColumn)
return QString::fromLatin1("%1:%2")
.arg(CMI::Utils::toString(info.line), CMI::Utils::toString(info.column));
else if (column == LengthColumn)
return CMI::Utils::toString(token.length());
else if (column == LengthInBytesColumn)
return CMI::Utils::toString(token.bytes());
else if (column == GeneratedColumn)
return CMI::Utils::toString(token.generated());
else if (column == ExpandedColumn)
......@@ -922,8 +922,8 @@ QVariant TokensModel::headerData(int section, Qt::Orientation orientation, int r
return QLatin1String("Offset");
case LineColumnNumberColumn:
return QLatin1String("Line:Column");
case LengthColumn:
return QLatin1String("Length");
case LengthInBytesColumn:
return QLatin1String("Bytes");
case GeneratedColumn:
return QLatin1String("Generated");
case ExpandedColumn:
......
......@@ -794,7 +794,7 @@ void CPPEditorWidget::markSymbolsNow()
if (column)
--column; // adjust the column position.
const int len = unit->tokenAt(index).length();
const int len = unit->tokenAt(index).bytes();
QTextCursor cursor(document()->findBlockByNumber(line - 1));
cursor.setPosition(cursor.position() + column);
......
......@@ -479,7 +479,8 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
for (int i = 0; i < tokens.size(); ++i) {
const Token &tk = tokens.at(i);
if (((unsigned) positionInBlock) >= tk.begin() && ((unsigned) positionInBlock) < tk.end()) {
if (((unsigned) positionInBlock) >= tk.bytesBegin()
&& ((unsigned) positionInBlock) < tk.bytesEnd()) {
int closingParenthesisPos = tokens.size();
if (i >= 2 && tokens.at(i).is(T_IDENTIFIER) && tokens.at(i - 1).is(T_LPAREN)
&& (tokens.at(i - 2).is(T_SIGNAL) || tokens.at(i - 2).is(T_SLOT))) {
......@@ -503,10 +504,10 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
if (closingParenthesisPos < tokens.size()) {
QTextBlock block = cursor.block();
beginOfToken = block.position() + tokens.at(i).begin();
endOfToken = block.position() + tokens.at(i).end();
beginOfToken = block.position() + tokens.at(i).bytesBegin();
endOfToken = block.position() + tokens.at(i).bytesEnd();
tc.setPosition(block.position() + tokens.at(closingParenthesisPos).end());
tc.setPosition(block.position() + tokens.at(closingParenthesisPos).bytesEnd());
recognizedQtMethod = true;
}
break;
......@@ -521,7 +522,8 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
// In this case we want to look at one token before the current position to recognize
// an operator if the cursor is inside the actual operator: operator[$]
if (unsigned(positionInBlock) >= tk.begin() && unsigned(positionInBlock) <= tk.end()) {
if (unsigned(positionInBlock) >= tk.bytesBegin()
&& unsigned(positionInBlock) <= tk.bytesEnd()) {
cursorRegionReached = true;
if (tk.is(T_OPERATOR)) {
link = attemptFuncDeclDef(cursor, m_widget, theSnapshot,
......@@ -531,7 +533,7 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
} else if (tk.isOperator() && i > 0 && tokens.at(i - 1).is(T_OPERATOR)) {
QTextCursor c = cursor;
c.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor,
positionInBlock - tokens.at(i - 1).begin());
positionInBlock - tokens.at(i - 1).bytesBegin());
link = attemptFuncDeclDef(c, m_widget, theSnapshot, documentFromSemanticInfo,
symbolFinder);
if (link.hasValidLinkText())
......@@ -560,8 +562,8 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
const Token tk = SimpleLexer::tokenAt(block.text(), pos,
BackwardsScanner::previousBlockState(block), true);
beginOfToken = block.position() + tk.begin();
endOfToken = block.position() + tk.end();
beginOfToken = block.position() + tk.bytesBegin();
endOfToken = block.position() + tk.bytesEnd();
// Handle include directives
if (tk.is(T_STRING_LITERAL) || tk.is(T_ANGLE_STRING_LITERAL)) {
......
......@@ -414,17 +414,17 @@ static bool hasCommentedName(
// maybe in a comment but in the right spot?
int nameStart = 0;
if (param->declarator)
nameStart = unit->tokenAt(param->declarator->lastToken() - 1).end();
nameStart = unit->tokenAt(param->declarator->lastToken() - 1).bytesEnd();
else if (param->type_specifier_list)
nameStart = unit->tokenAt(param->type_specifier_list->lastToken() - 1).end();
nameStart = unit->tokenAt(param->type_specifier_list->lastToken() - 1).bytesEnd();
else
nameStart = unit->tokenAt(param->firstToken()).begin();
nameStart = unit->tokenAt(param->firstToken()).bytesBegin();
int nameEnd = 0;
if (param->equal_token)
nameEnd = unit->tokenAt(param->equal_token).begin();
nameEnd = unit->tokenAt(param->equal_token).bytesBegin();
else
nameEnd = unit->tokenAt(param->lastToken()).begin(); // one token after
nameEnd = unit->tokenAt(param->lastToken()).bytesBegin(); // one token after
QString text = source.mid(nameStart, nameEnd - nameStart);
......
......@@ -108,7 +108,7 @@ void CppHighlighter::highlightBlock(const QString &text)
return;
}
const unsigned firstNonSpace = tokens.first().begin();
const unsigned firstNonSpace = tokens.first().bytesBegin();
Parentheses parentheses;
parentheses.reserve(20); // assume wizard level ;-)
......@@ -122,29 +122,32 @@ void CppHighlighter::highlightBlock(const QString &text)
unsigned previousTokenEnd = 0;
if (i != 0) {
// mark the whitespaces
previousTokenEnd = tokens.at(i - 1).begin() +
tokens.at(i - 1).length();
previousTokenEnd = tokens.at(i - 1).bytesBegin() +
tokens.at(i - 1).bytes();
}
if (previousTokenEnd != tk.begin())
setFormat(previousTokenEnd, tk.begin() - previousTokenEnd, formatForCategory(CppVisualWhitespace));
if (previousTokenEnd != tk.bytesBegin()) {
setFormat(previousTokenEnd,
tk.bytesBegin() - previousTokenEnd,
formatForCategory(CppVisualWhitespace));
}
if (tk.is(T_LPAREN) || tk.is(T_LBRACE) || tk.is(T_LBRACKET)) {
const QChar c = text.at(tk.begin());
parentheses.append(Parenthesis(Parenthesis::Opened, c, tk.begin()));
const QChar c = text.at(tk.bytesBegin());
parentheses.append(Parenthesis(Parenthesis::Opened, c, tk.bytesBegin()));