aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-02-08 15:20:02 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-02-13 12:50:05 +0000
commitc9fb3900d92041fa7a2d3cbe2d689696343bd973 (patch)
tree7f9f6ebec2f5eb0b5ebe1c3803cb1bacdabd6f02 /sources
parent7d32f709db114c32bc10abf15f3c9b733224be2f (diff)
Refactor QtDocGenerator::writeFormattedText()
Rewrite to use QStringRef and add some checks preventing overflow should the text contain empty lines. Task-number: PYSIDE-363 Change-Id: I850221bc6e7a6b88fc3b6078cf2cb2e01663ab15 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
index 35f7de2c9..17671de2d 100644
--- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
+++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
@@ -1102,17 +1102,24 @@ void QtDocGenerator::writeFormattedText(QTextStream &s, const Documentation &doc
QtXmlToSphinx x(this, doc.value(), metaClassName);
s << x;
} else {
- const QStringList lines = doc.value().split(QLatin1Char('\n'));
- QRegExp regex(QLatin1String("\\S")); // non-space character
+ const QString &value = doc.value();
+ const QVector<QStringRef> lines = value.splitRef(QLatin1Char('\n'));
int typesystemIndentation = std::numeric_limits<int>().max();
// check how many spaces must be removed from the beginning of each line
- for (const QString &line : lines) {
- int idx = line.indexOf(regex);
- if (idx >= 0)
- typesystemIndentation = qMin(typesystemIndentation, idx);
+ for (const QStringRef &line : lines) {
+ const auto it = std::find_if(line.cbegin(), line.cend(),
+ [] (QChar c) { return !c.isSpace(); });
+ if (it != line.cend())
+ typesystemIndentation = qMin(typesystemIndentation, int(it - line.cbegin()));
+ }
+ if (typesystemIndentation == std::numeric_limits<int>().max())
+ typesystemIndentation = 0;
+ for (const QStringRef &line : lines) {
+ s << INDENT
+ << (typesystemIndentation > 0 && typesystemIndentation < line.size()
+ ? line.right(line.size() - typesystemIndentation) : line)
+ << endl;
}
- for (QString line : lines)
- s << INDENT << line.remove(0, typesystemIndentation) << endl;
}
s << endl;