diff options
author | Paul Wicking <paul.wicking@qt.io> | 2023-09-26 10:48:51 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2023-09-30 19:51:41 +0200 |
commit | 25575b905fb6d6d97928595f850db5a6d3a3c7a0 (patch) | |
tree | 464bbda23ab91ece2db74bbcadf0693ed7f55874 | |
parent | 9e451480c8ac40f0de9697d038f56c5af1aec5a9 (diff) |
QDoc: Refactor XmlGenerator::rewritePropertyBrief
- Flatten the method by inverting two conditional checks. This allows
for dedenting the bulk of the method.
- Replace lengthy "or" condition with a QStringList and use of it's
.contains() method.
- const qualify local variable that doesn't mutate.
Task-number: QTBUG-117470
Change-Id: I80d64111bf4a62f0eb2bb6aa4d8ae4cd13d3e28a
Reviewed-by: Luca Di Sera <luca.disera@qt.io>
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
(cherry picked from commit e549711704b1d6efd79ff743b2f44fc2ebee2062)
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
(cherry picked from commit e5912919ab571908c3ba7f11ddbd08cdf1b06fab)
-rw-r--r-- | src/qdoc/xmlgenerator.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/qdoc/xmlgenerator.cpp b/src/qdoc/xmlgenerator.cpp index ff74ce2e4..0c8e10bee 100644 --- a/src/qdoc/xmlgenerator.cpp +++ b/src/qdoc/xmlgenerator.cpp @@ -93,22 +93,21 @@ int XmlGenerator::hOffset(const Node *node) */ void XmlGenerator::rewritePropertyBrief(const Atom *atom, const Node *relative) { - if (relative->nodeType() == Node::Property || relative->nodeType() == Node::Variable) { - atom = atom->next(); - if (atom && atom->type() == Atom::String) { - QString firstWord = - atom->string().toLower().section(' ', 0, 0, QString::SectionSkipEmpty); - if (firstWord == QLatin1String("the") || firstWord == QLatin1String("a") - || firstWord == QLatin1String("an") || firstWord == QLatin1String("whether") - || firstWord == QLatin1String("which")) { - QString str = QLatin1String("This ") - + QLatin1String(relative->nodeType() == Node::Property ? "property" - : "variable") - + QLatin1String(" holds ") + atom->string().left(1).toLower() - + atom->string().mid(1); - const_cast<Atom *>(atom)->setString(str); - } - } + if (relative->nodeType() != Node::Property && relative->nodeType() != Node::Variable) + return; + atom = atom->next(); + if (!atom || atom->type() != Atom::String) + return; + + const QString firstWord = + atom->string().toLower().section(' ', 0, 0, QString::SectionSkipEmpty); + const QStringList words{ "the", "a", "an", "whether", "which" }; + if (words.contains(firstWord)) { + QString str = QLatin1String("This ") + + QLatin1String(relative->nodeType() == Node::Property ? "property" : "variable") + + QLatin1String(" holds ") + atom->string().left(1).toLower() + + atom->string().mid(1); + const_cast<Atom *>(atom)->setString(str); } } |