aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/textstream.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-19 15:46:33 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-23 13:23:30 +0100
commit2cfe8433c861c3602e5e23af8d4fdfb6fd219f4d (patch)
treea3bd3efb75f8e4de3f9b2e27c80db77505d47519 /sources/shiboken6/ApiExtractor/textstream.cpp
parentab8d43efb06ad00f8be945efde7a11279eda44fa (diff)
Documentation: Fix most sphinx errors "Inline strong start-string without end-string."
Ensure characters following a formatting end are escaped by adding handling and some RST manipulators to class TextStream. Task-number: PYSIDE-1112 Pick-to: 6.2 Change-Id: I167160cd18fd890d73e31738487d2c91e012196c Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/textstream.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/textstream.cpp62
1 files changed, 60 insertions, 2 deletions
diff --git a/sources/shiboken6/ApiExtractor/textstream.cpp b/sources/shiboken6/ApiExtractor/textstream.cpp
index 364634f2d..2b8e9f29b 100644
--- a/sources/shiboken6/ApiExtractor/textstream.cpp
+++ b/sources/shiboken6/ApiExtractor/textstream.cpp
@@ -75,6 +75,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 +93,11 @@ void TextStream::putRepetitiveChars(char c, int count)
}
}
+void TextStream::_setRstFormattingEnd()
+{
+ m_rstFormattingEnd = true;
+}
+
void TextStream::setLastCharClass(CharClass c)
{
m_lastCharClass = c;
@@ -110,6 +121,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 +140,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 +158,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 +174,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;
}
@@ -228,3 +253,36 @@ void ensureEndl(TextStream &s)
if (s.lastChar() != QLatin1Char('\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();
+}