diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor/textstream.h')
-rw-r--r-- | sources/shiboken6/ApiExtractor/textstream.h | 84 |
1 files changed, 52 insertions, 32 deletions
diff --git a/sources/shiboken6/ApiExtractor/textstream.h b/sources/shiboken6/ApiExtractor/textstream.h index dff79b939..228f36405 100644 --- a/sources/shiboken6/ApiExtractor/textstream.h +++ b/sources/shiboken6/ApiExtractor/textstream.h @@ -1,35 +1,11 @@ -/**************************************************************************** -** -** 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 #ifndef TEXTSTREAM_H #define TEXTSTREAM_H #include <QtCore/QTextStream> +#include <QtCore/QString> /// A text stream based on QTextStream with built-in indent. class TextStream @@ -46,7 +22,7 @@ public: enum class CharClass { - Other, NewLine, Hash + Other, NewLine, Space, Hash, BackSlash }; explicit TextStream(QIODevice *device, Language l = Language::None); @@ -55,7 +31,7 @@ public: virtual ~TextStream(); Language language() const { return m_language; } - void setLanguage(const Language &language) { m_language = language; } + void setLanguage(Language language) { m_language = language; } bool isIndentationEnabled() const { return m_indentationEnabled; } void setIndentationEnabled(bool m) @@ -79,8 +55,7 @@ public: { return m_str.fieldAlignment(); } void setFieldAlignment(QTextStream::FieldAlignment al) { m_str.setFieldAlignment(al); } - void setString(QString *string, QIODeviceBase::OpenMode openMode = QIODeviceBase::ReadWrite) - { m_str.setString(string, openMode); } + void setString(QString *string, QIODeviceBase::OpenMode openMode = QIODeviceBase::ReadWrite); QString *string() const { return m_str.string(); } void flush() { m_str.flush(); } void setDevice(QIODevice *device) { m_str.setDevice(device); } @@ -98,7 +73,14 @@ public: void putInt(int t); void putSizeType(qsizetype t); + void putRawString(const char *s) { m_str << s; } + void putRawChar(char c) { m_str << c; } + TextStream &operator<<(QStringView v) { putString(v); return *this; } + TextStream &operator<<(const QString &qs) { putString(QStringView{qs}); return *this; } + TextStream &operator<<(QLatin1StringView lv) { putString(lv.constData()); return *this; } + TextStream &operator<<(QUtf8StringView uv) { putString(uv.data()); return *this; } + TextStream &operator<<(const QByteArray &ba) { putString(ba.constData()); return *this; } TextStream &operator<<(QChar c) { putChar(c); return *this; } TextStream &operator<<(const char *s) { putString(s); return *this; } TextStream &operator<<(char c) { putChar(c); return *this; } @@ -107,11 +89,13 @@ public: TextStream &operator<<(qsizetype t) { putSizeType(t); return *this; } #endif - inline TextStream &operator<<(QTextStreamManipulator m) { m_str << m; return *this; } + inline TextStream &operator<<(const QTextStreamManipulator &m) { m_str << m; return *this; } inline TextStream &operator<<(ManipulatorFunc f) { f(*this); return *this; } void putRepetitiveChars(char c, int count); + void _setRstFormattingEnd(); + protected: void setLastCharClass(CharClass c); @@ -126,6 +110,7 @@ private: int m_tabWidth = 4; int m_indentation = 0; bool m_indentationEnabled = true; + bool m_rstFormattingEnd = false; // just past some **bla** where '\' needs to be enforced Language m_language; }; @@ -152,6 +137,19 @@ void disableIndent(TextStream &s); // Works only for streams on strings void ensureEndl(TextStream &s); +void rstBold(TextStream &s); +void rstBoldOff(TextStream &s); +void rstCode(TextStream &s); +void rstCodeOff(TextStream &s); +void rstItalic(TextStream &s); +void rstItalicOff(TextStream &s); + +inline TextStream &operator<<(TextStream &str, QAnyStringView asv) +{ + asv.visit([&str](auto s) { str << s; }); + return str; +} + /// Format an aligned field template <class T> class AlignedField @@ -191,6 +189,28 @@ TextStream &operator<<(TextStream &str, const AlignedField<T> &fa) return str; } +class Pad +{ +public: + explicit Pad(char c, int count) : m_char(c), m_count(count) {} + + void write(TextStream &str) const + { + for (int i = 0; i < m_count; ++i) + str << m_char; + } + +private: + const char m_char; + const int m_count; +}; + +inline TextStream &operator<<(TextStream &str, const Pad &pad) +{ + pad.write(str); + return str; +} + class Indentation { public: |