diff --git a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp index 316cd1a6..e3ca8cd0 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp @@ -15,6 +15,7 @@ #include "liveliness_utils.hpp" #include +#include #include "rcpputils/scope_exit.hpp" #include "rcutils/logging_macros.h" @@ -158,6 +159,41 @@ std::optional Entity::make( return std::move(entity); } +namespace +{ +///============================================================================= +std::vector split_keyexpr( + const std::string & keyexpr, + const char delim = '/') +{ + std::vector delim_idx = {}; + // Insert -1 for starting position to make the split easier when using substr. + delim_idx.push_back(-1); + std::size_t idx = 0; + for (auto it = keyexpr.begin(); it != keyexpr.end(); ++it) { + if (*it == delim) { + delim_idx.push_back(idx); + } + ++idx; + } + std::vector result = {}; + try { + for (std::size_t i = 1; i < delim_idx.size(); ++i) { + const auto & prev_idx = delim_idx.at(i - 1); + const auto & idx = delim_idx.at(i); + result.push_back(keyexpr.substr(prev_idx + 1, idx - prev_idx - 1)); + } + } catch (const std::exception & e) { + printf("%s\n", e.what()); + return {}; + } + // Finally add the last substr. + result.push_back(keyexpr.substr(delim_idx.back() + 1)); + return result; +} + +} // namespace + ///============================================================================= std::optional Entity::make(const std::string & keyexpr) { @@ -308,35 +344,4 @@ bool PublishToken::del( return true; } -///============================================================================= -std::vector split_keyexpr( - const std::string & keyexpr, - const char delim) -{ - std::vector delim_idx = {}; - // Insert -1 for starting position to make the split easier when using substr. - delim_idx.push_back(-1); - std::size_t idx = 0; - for (auto it = keyexpr.begin(); it != keyexpr.end(); ++it) { - if (*it == delim) { - delim_idx.push_back(idx); - } - ++idx; - } - std::vector result = {}; - try { - for (std::size_t i = 1; i < delim_idx.size(); ++i) { - const auto & prev_idx = delim_idx.at(i - 1); - const auto & idx = delim_idx.at(i); - result.push_back(keyexpr.substr(prev_idx + 1, idx - prev_idx - 1)); - } - } catch (const std::exception & e) { - printf("%s\n", e.what()); - return {}; - } - // Finally add the last substr. - result.push_back(keyexpr.substr(delim_idx.back() + 1)); - return result; -} - } // namespace liveliness diff --git a/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp b/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp index 1a1d58fb..a1a99d9d 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp @@ -126,12 +126,6 @@ class PublishToken const std::string & token); }; -///============================================================================= -/// Split a liveliness token's expression into parts based on a delimiter. -std::vector split_keyexpr( - const std::string & keyexpr, - const char delim = '/'); - } // namespace liveliness #endif // DETAIL__LIVELINESS_UTILS_HPP_