From 6fe82385d6110dcfc0b0bb6e493b726405610c6a Mon Sep 17 00:00:00 2001 From: Tim Jenssen Date: Tue, 19 Jul 2016 14:47:52 +0000 Subject: [PATCH] Revert "Clang: Inline LinePrefixer" This reverts commit 3ea1eb363103e0bbd629f00f97ccdf1dd6226f90. not performance relevant Change-Id: I3e0a4bdf2317c5eec858c7661b2e67fe8028aff5 Reviewed-by: Marco Bubke Reviewed-by: hjk --- .../clangbackendipc/clangbackendipc-lib.pri | 1 + src/libs/clangbackendipc/lineprefixer.cpp | 56 +++++++++++++++++++ src/libs/clangbackendipc/lineprefixer.h | 35 ++---------- 3 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 src/libs/clangbackendipc/lineprefixer.cpp diff --git a/src/libs/clangbackendipc/clangbackendipc-lib.pri b/src/libs/clangbackendipc/clangbackendipc-lib.pri index 4762d8ad624..3425c9623a3 100644 --- a/src/libs/clangbackendipc/clangbackendipc-lib.pri +++ b/src/libs/clangbackendipc/clangbackendipc-lib.pri @@ -32,6 +32,7 @@ SOURCES += $$PWD/clangcodemodelserverinterface.cpp \ $$PWD/codecompletionchunk.cpp \ $$PWD/projectpartcontainer.cpp \ $$PWD/projectpartsdonotexistmessage.cpp \ + $$PWD/lineprefixer.cpp \ $$PWD/clangbackendipcdebugutils.cpp \ $$PWD/diagnosticcontainer.cpp \ $$PWD/sourcerangecontainer.cpp \ diff --git a/src/libs/clangbackendipc/lineprefixer.cpp b/src/libs/clangbackendipc/lineprefixer.cpp new file mode 100644 index 00000000000..12adfa95c78 --- /dev/null +++ b/src/libs/clangbackendipc/lineprefixer.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** 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 diff --git a/src/libs/clangbackendipc/lineprefixer.h b/src/libs/clangbackendipc/lineprefixer.h index 86a8cba96be..b2607720fe9 100644 --- a/src/libs/clangbackendipc/lineprefixer.h +++ b/src/libs/clangbackendipc/lineprefixer.h @@ -25,10 +25,9 @@ #pragma once -#include - #include #include +#include namespace ClangBackEnd { @@ -36,36 +35,12 @@ class LinePrefixer { public: LinePrefixer() = delete; - LinePrefixer(const QByteArray &prefix) - : 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; - } + LinePrefixer(const QByteArray &m_prefix); + QByteArray prefix(const QByteArray &text); private: - QByteArray prefix_; - bool previousIsEndingWithNewLine; + QByteArray m_prefix; + bool m_previousIsEndingWithNewLine; }; } // namespace ClangBackEnd