aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/textstream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/ApiExtractor/textstream.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/textstream.cpp93
1 files changed, 63 insertions, 30 deletions
diff --git a/sources/shiboken6/ApiExtractor/textstream.cpp b/sources/shiboken6/ApiExtractor/textstream.cpp
index 364634f2d..83d981b2b 100644
--- a/sources/shiboken6/ApiExtractor/textstream.cpp
+++ b/sources/shiboken6/ApiExtractor/textstream.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** 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.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "textstream.h"
@@ -75,6 +50,12 @@ qint64 TextStream::pos() const
return m_str.pos();
}
+void TextStream::setString(QString *string, QIODeviceBase::OpenMode openMode)
+{
+ m_str.setString(string, openMode);
+ m_rstFormattingEnd = false;
+}
+
void TextStream::putRepetitiveChars(char c, int count)
{
if (count > 0) {
@@ -87,6 +68,11 @@ void TextStream::putRepetitiveChars(char c, int count)
}
}
+void TextStream::_setRstFormattingEnd()
+{
+ m_rstFormattingEnd = true;
+}
+
void TextStream::setLastCharClass(CharClass c)
{
m_lastCharClass = c;
@@ -110,6 +96,11 @@ static TextStream::CharClass charClassHelper(Char c)
return TextStream::CharClass::NewLine;
case '#':
return TextStream::CharClass::Hash;
+ case ' ':
+ case '\t':
+ return TextStream::CharClass::Space;
+ case '\\':
+ return TextStream::CharClass::BackSlash;
default:
break;
}
@@ -124,6 +115,13 @@ static inline TextStream::CharClass charClass(QChar c)
void TextStream::checkIndent(CharClass upComingCharClass)
{
+ if (m_rstFormattingEnd) {
+ if (upComingCharClass != CharClass::Space && upComingCharClass != CharClass::NewLine
+ && upComingCharClass != CharClass::BackSlash) {
+ m_str << '\\';
+ }
+ m_rstFormattingEnd = false;
+ }
if (m_indentationEnabled && m_lastCharClass == CharClass::NewLine
&& (upComingCharClass != CharClass::NewLine
&& (m_language != Language::Cpp || upComingCharClass != CharClass::Hash))) {
@@ -135,7 +133,8 @@ void TextStream::checkIndent(CharClass upComingCharClass)
template <class Char>
void TextStream::putCharHelper(Char c)
{
- checkIndent(charClass(c));
+ const auto klass = charClass(c);
+ checkIndent(klass);
m_str << c;
}
@@ -150,7 +149,8 @@ void TextStream::putString(QStringView v)
// If there is no newline, write as a blob. This is important to make
// field formatting (alignment/width) working, else each char will be
// considered a field.
- checkIndent(charClass(*v.cbegin()));
+ const auto klass = charClass(*v.cbegin());
+ checkIndent(klass);
m_str << v;
m_lastCharClass = CharClass::Other;
}
@@ -225,6 +225,39 @@ void disableIndent(TextStream &s)
void ensureEndl(TextStream &s)
{
- if (s.lastChar() != QLatin1Char('\n'))
+ if (s.lastChar() != u'\n')
s << '\n';
}
+
+void rstBold(TextStream &s)
+{
+ s.putRawString("**");
+}
+
+void rstBoldOff(TextStream &s)
+{
+ s.putRawString("**");
+ s._setRstFormattingEnd();
+}
+
+void rstItalic(TextStream &s)
+{
+ s.putRawChar('*');
+}
+
+void rstItalicOff(TextStream &s)
+{
+ s.putRawChar('*');
+ s._setRstFormattingEnd();
+}
+
+void rstCode(TextStream &s)
+{
+ s.putRawString("``");
+}
+
+void rstCodeOff(TextStream &s)
+{
+ s.putRawString("``");
+ s._setRstFormattingEnd();
+}