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

Method checkCommonLevel

src/backend/datasources/MQTTClient.cpp:597–643  ·  view source on GitHub ↗

! *\brief Returns the '+' wildcard containing topic name, which includes the given topic names * * \param first the name of a topic * \param second the name of a topic * \return The name of the common topic, if it exists, otherwise an empty string */

Source from the content-addressed store, hash-verified

595 * \return The name of the common topic, if it exists, otherwise an empty string
596 */
597QString MQTTClient::checkCommonLevel(const QString& first, const QString& second) {
598 QStringList firstList = first.split(QLatin1Char('/'), Qt::SkipEmptyParts);
599 QStringList secondtList = second.split(QLatin1Char('/'), Qt::SkipEmptyParts);
600 QString commonTopic;
601
602 if (!firstList.isEmpty()) {
603 // the two topics have to be the same size and can't be identic
604 if ((firstList.size() == secondtList.size()) && (first != second)) {
605 // the index where they differ
606 int differIndex = -1;
607 for (int i = 0; i < firstList.size(); ++i) {
608 if (firstList.at(i) != secondtList.at(i)) {
609 differIndex = i;
610 break;
611 }
612 }
613
614 // they can differ at only one level and that can't be the first
615 bool differ = false;
616 if (differIndex > 0) {
617 for (int j = differIndex + 1; j < firstList.size(); ++j) {
618 if (firstList.at(j) != secondtList.at(j)) {
619 differ = true;
620 break;
621 }
622 }
623 } else
624 differ = true;
625
626 if (!differ) {
627 for (int i = 0; i < firstList.size(); ++i) {
628 if (i != differIndex) {
629 commonTopic.append(firstList.at(i));
630 } else {
631 // we put '+' wildcard at the level where they differ
632 commonTopic.append(QStringLiteral("+"));
633 }
634
635 if (i != firstList.size() - 1)
636 commonTopic.append(QStringLiteral("/"));
637 }
638 }
639 }
640 }
641 // qDebug() << first << " " << second << " common topic: "<<commonTopic;
642 return commonTopic;
643}
644
645void MQTTClient::setWillSettings(const MQTTWill& settings) {
646 m_MQTTWill = settings;

Callers 2

testCommonTrueMethod · 0.45
testCommonFalseMethod · 0.45

Calls 4

splitMethod · 0.80
appendMethod · 0.80
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by 2

testCommonTrueMethod · 0.36
testCommonFalseMethod · 0.36