MCPcopy Create free account
hub / github.com/KDE/labplot / checkTopicContains

Method checkTopicContains

src/backend/datasources/MQTTClient.cpp:555–588  ·  view source on GitHub ↗

! *\brief Checks if a topic contains another one * * \param superior the name of a topic * \param inferior the name of a topic * \return true if superior is equal to or contains(if superior contains wildcards) inferior, * false otherwise */

Source from the content-addressed store, hash-verified

553 * false otherwise
554 */
555bool MQTTClient::checkTopicContains(const QString& superior, const QString& inferior) {
556 if (superior == inferior)
557 return true;
558 else {
559 if (superior.contains(QLatin1String("/"))) {
560 QStringList superiorList = superior.split(QLatin1Char('/'), Qt::SkipEmptyParts);
561 QStringList inferiorList = inferior.split(QLatin1Char('/'), Qt::SkipEmptyParts);
562
563 // a longer topic can't contain a shorter one
564 if (superiorList.size() > inferiorList.size())
565 return false;
566
567 bool ok = true;
568 for (int i = 0; i < superiorList.size(); ++i) {
569 if (superiorList.at(i) != inferiorList.at(i)) {
570 if ((superiorList.at(i) != QLatin1Char('+')) && !(superiorList.at(i) == QLatin1Char('#') && i == superiorList.size() - 1)) {
571 // if the two topics differ, and the superior's current level isn't + or #(which can be only in the last position)
572 // then superior can't contain inferior
573 ok = false;
574 break;
575 } else if (i == superiorList.size() - 1 && (superiorList.at(i) == QLatin1Char('+') && inferiorList.at(i) == QLatin1Char('#'))) {
576 // if the two topics differ at the last level
577 // and the superior's current level is + while the inferior's is #(which can be only in the last position)
578 // then superior can't contain inferior
579 ok = false;
580 break;
581 }
582 }
583 }
584 return ok;
585 }
586 return false;
587 }
588}
589
590/*!
591 *\brief Returns the '+' wildcard containing topic name, which includes the given topic names

Callers 2

testContainFalseMethod · 0.45
testContainTrueMethod · 0.45

Calls 3

splitMethod · 0.80
containsMethod · 0.45
sizeMethod · 0.45

Tested by 2

testContainFalseMethod · 0.36
testContainTrueMethod · 0.36