Commit 6bbee896 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

QtSupport: Deduplicate code in QtOutputFormatter

Change-Id: I79a1c51fb52c66561d44acfb9c26c5ec24ca6e52
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 3f1fd49c
......@@ -109,71 +109,30 @@ void QtOutputFormatter::appendMessagePart(QTextCursor &cursor, const QString &tx
{
QString deferredText;
int start = 0;
int pos = txt.indexOf(QLatin1Char('\n'));
while (pos != -1) {
// Line identified
if (!m_lastLine.isEmpty()) {
// Line continuation
const QString newPart = txt.mid(start, pos - start + 1);
const QString line = m_lastLine + newPart;
LinkResult lr = matchLine(line);
if (!lr.href.isEmpty()) {
// Found something && line continuation
cursor.insertText(deferredText, format);
deferredText.clear();
const int length = txt.length();
for (int start = 0, pos = -1; start < length; start = pos + 1) {
pos = txt.indexOf(QLatin1Char('\n'), start);
const QString newPart = txt.mid(start, (pos == -1) ? -1 : pos - start + 1);
const QString line = m_lastLine + newPart;
LinkResult lr = matchLine(line);
if (!lr.href.isEmpty()) {
// Found something && line continuation
cursor.insertText(deferredText, format);
deferredText.clear();
if (!m_lastLine.isEmpty())
clearLastLine();
appendLine(cursor, lr, line, format);
} else {
// Found nothing, just emit the new part
deferredText += newPart;
}
// Handled line continuation
m_lastLine.clear();
appendLine(cursor, lr, line, format);
} else {
const QString line = txt.mid(start, pos - start + 1);
LinkResult lr = matchLine(line);
if (!lr.href.isEmpty()) {
cursor.insertText(deferredText, format);
deferredText.clear();
appendLine(cursor, lr, line, format);
} else {
deferredText += line;
}
// Found nothing, just emit the new part
deferredText += newPart;
}
start = pos + 1;
pos = txt.indexOf(QLatin1Char('\n'), start);
}
// Handle left over stuff
if (start < txt.length()) {
if (!m_lastLine.isEmpty()) {
// Line continuation
const QString newPart = txt.mid(start);
const QString line = m_lastLine + newPart;
LinkResult lr = matchLine(line);
if (!lr.href.isEmpty()) {
// Found something && line continuation
cursor.insertText(deferredText, format);
deferredText.clear();
clearLastLine();
appendLine(cursor, lr, line, format);
} else {
// Found nothing, just emit the new part
deferredText += newPart;
}
if (pos == -1) {
m_lastLine = line;
} else {
m_lastLine = txt.mid(start);
LinkResult lr = matchLine(m_lastLine);
if (!lr.href.isEmpty()) {
cursor.insertText(deferredText, format);
deferredText.clear();
appendLine(cursor, lr, m_lastLine, format);
} else {
deferredText += m_lastLine;
}
break;
}
m_lastLine.clear(); // Handled line continuation
}
cursor.insertText(deferredText, format);
}
......
Markdown is supported
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