bool Subscription::IsValidTopicName()

in src/mqtt/Common.cpp [107:140]


        bool Subscription::IsValidTopicName(util::String p_topic_name) {
            if (1 == p_topic_name.length()) {
                if (RESERVED_TOPIC == p_topic_name[0]) {
                    return false;
                }
                else {
                    return true;
                }
            }

            util::String::iterator it;
            for (it = p_topic_name.begin(); it < p_topic_name.end(); ++it) {
                if (*it == SINGLE_LEVEL_WILDCARD) {
                    if (it == p_topic_name.begin()) {
                        if (*(it + 1) != '/' && it + 1 != p_topic_name.end()) {
                            return false;
                        }
                    } else if (it + 1 == p_topic_name.end()) {
                        if (*(it - 1) != '/') {
                            return false;
                        }
                    } else if (*(it - 1) != '/' || *(it + 1) != '/') {
                        return false;
                    }
                } else if (*it == MULTI_LEVEL_WILDCARD) {
                    if (it + 1 != p_topic_name.end()) {
                        return false;
                    } else if (it != p_topic_name.begin() && *(it - 1) != '/') {
                        return false;
                    }
                }
            }
            return true;
        }