forked from qt-creator/qt-creator
Clang: Inline LinePrefixer
Change-Id: I5e55f8c9912d5be5102a5cdf5eb795b786dc1282 Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
@@ -32,7 +32,6 @@ SOURCES += $$PWD/clangcodemodelserverinterface.cpp \
|
|||||||
$$PWD/codecompletionchunk.cpp \
|
$$PWD/codecompletionchunk.cpp \
|
||||||
$$PWD/projectpartcontainer.cpp \
|
$$PWD/projectpartcontainer.cpp \
|
||||||
$$PWD/projectpartsdonotexistmessage.cpp \
|
$$PWD/projectpartsdonotexistmessage.cpp \
|
||||||
$$PWD/lineprefixer.cpp \
|
|
||||||
$$PWD/clangbackendipcdebugutils.cpp \
|
$$PWD/clangbackendipcdebugutils.cpp \
|
||||||
$$PWD/diagnosticcontainer.cpp \
|
$$PWD/diagnosticcontainer.cpp \
|
||||||
$$PWD/sourcerangecontainer.cpp \
|
$$PWD/sourcerangecontainer.cpp \
|
||||||
|
@@ -1,56 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "lineprefixer.h"
|
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
|
||||||
|
|
||||||
LinePrefixer::LinePrefixer(const QByteArray &prefix)
|
|
||||||
: m_prefix(prefix)
|
|
||||||
, m_previousIsEndingWithNewLine(true)
|
|
||||||
{}
|
|
||||||
|
|
||||||
QByteArray LinePrefixer::prefix(const QByteArray &text)
|
|
||||||
{
|
|
||||||
QByteArray output = text;
|
|
||||||
|
|
||||||
if (m_previousIsEndingWithNewLine)
|
|
||||||
output.prepend(m_prefix);
|
|
||||||
|
|
||||||
if (output.endsWith('\n')) {
|
|
||||||
m_previousIsEndingWithNewLine = true;
|
|
||||||
output.chop(1);
|
|
||||||
} else {
|
|
||||||
m_previousIsEndingWithNewLine = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
output.replace("\n", "\n" + m_prefix);
|
|
||||||
if (m_previousIsEndingWithNewLine)
|
|
||||||
output.append('\n');
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
|
@@ -25,9 +25,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <utf8string.h>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <utf8string.h>
|
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
@@ -35,12 +36,36 @@ class LinePrefixer
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LinePrefixer() = delete;
|
LinePrefixer() = delete;
|
||||||
LinePrefixer(const QByteArray &m_prefix);
|
LinePrefixer(const QByteArray &prefix)
|
||||||
QByteArray prefix(const QByteArray &text);
|
: prefix_(prefix),
|
||||||
|
previousIsEndingWithNewLine(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray prefix(const QByteArray &text)
|
||||||
|
{
|
||||||
|
QByteArray output = text;
|
||||||
|
|
||||||
|
if (previousIsEndingWithNewLine)
|
||||||
|
output.prepend(prefix_);
|
||||||
|
|
||||||
|
if (output.endsWith('\n')) {
|
||||||
|
previousIsEndingWithNewLine = true;
|
||||||
|
output.chop(1);
|
||||||
|
} else {
|
||||||
|
previousIsEndingWithNewLine = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
output.replace("\n", "\n" + prefix_);
|
||||||
|
if (previousIsEndingWithNewLine)
|
||||||
|
output.append('\n');
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray m_prefix;
|
QByteArray prefix_;
|
||||||
bool m_previousIsEndingWithNewLine;
|
bool previousIsEndingWithNewLine;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
Reference in New Issue
Block a user