From c9fb3900d92041fa7a2d3cbe2d689696343bd973 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 8 Feb 2018 15:20:02 +0100 Subject: 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 --- .../shiboken2/generator/qtdoc/qtdocgenerator.cpp | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'sources/shiboken2/generator') 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 lines = value.splitRef(QLatin1Char('\n')); int typesystemIndentation = std::numeric_limits().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().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; -- cgit v1.2.3