Commit 998e4ae1 authored by Andre Hartmann's avatar Andre Hartmann Committed by Roberto Raggi
Browse files

Fix C++ Macro Usages definition line in Search Results.

Add the complete line to the Search Results window,
including '#', "define", macro and macro value and
all possible white spaces between them.
Also covers the case of line continuation in macro
definitions from commit 3dec4855


Task-number: QTCREATORBUG-7217

Change-Id: I8b9d0c23d31ef76244833a9b9d67469c5c4a5635
Reviewed-by: default avatarRoberto Raggi <>
parent 4f0170e5
...@@ -646,14 +646,13 @@ void CppFindReferences::findMacroUses(const Macro &macro) ...@@ -646,14 +646,13 @@ void CppFindReferences::findMacroUses(const Macro &macro)
{ {
// ### FIXME: Encoding? // ### FIXME: Encoding?
const QByteArray &source = getSource(macro.fileName(), workingCopy).toLatin1(); const QByteArray &source = getSource(macro.fileName(), workingCopy).toLatin1();
QByteArray line = source.mid(macro.offset(), macro.length()); int lineBegin = source.lastIndexOf('\n', macro.offset()) + 1;
const int macroNameOffset = line.indexOf(; int lineEnd = source.indexOf('\n', macro.offset());
const int macroNameLength =; if (lineEnd == -1)
const int possibleNewLine = line.indexOf('\n', macroNameOffset + macroNameLength); lineEnd = source.length();
if (possibleNewLine != -1) const QByteArray line = source.mid(lineBegin, lineEnd - lineBegin);
line.truncate(possibleNewLine); // truncate line at first '\n' after macro name
search->addResult(macro.fileName(), macro.line(), line, search->addResult(macro.fileName(), macro.line(), line,
macroNameOffset, macroNameLength); line.indexOf(,;
} }
QFuture<Usage> result; QFuture<Usage> result;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment