From a136fe2bdb653adaa7ea817203abe1e576b29ac6 Mon Sep 17 00:00:00 2001 From: Shivang Vijay Date: Sun, 10 Mar 2024 11:47:27 +0530 Subject: [PATCH] Remove code duplication, update ros_topic_name_to_zenoh_key function --- rmw_zenoh_cpp/src/detail/liveliness_utils.cpp | 18 ------------------ rmw_zenoh_cpp/src/detail/liveliness_utils.hpp | 3 --- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 16 +++------------- 3 files changed, 3 insertions(+), 34 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp index 306c60a0..997f76b3 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp @@ -446,24 +446,6 @@ std::string mangle_name(const std::string & input) return output; } -///============================================================================= -char * mangle_name(const char * input) -{ - size_t input_length = strlen(input); - char * output = new char[input_length + 1]; - - for (size_t i = 0; i < input_length; ++i) { - if (input[i] == '/') { - output[i] = SLASH_REPLACEMENT; - } else { - output[i] = input[i]; - } - } - output[input_length] = '\0'; - - return output; -} - ///============================================================================= std::string demangle_name(const std::string & input) { diff --git a/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp b/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp index 40d9c80a..390ecc68 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp @@ -122,9 +122,6 @@ class Entity /// Replace "/" instances with "%". std::string mangle_name(const std::string & input); -/// Replace "/" instances with "%". -char * mangle_name(const char * input); - /// Replace "%" instances with "/". std::string demangle_name(const std::string & input); diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index de6edd11..fa120931 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -87,22 +87,12 @@ z_owned_keyexpr_t ros_topic_name_to_zenoh_key(const char * topic_name, size_t do size_t topic_name_len = strlen(topic_name); size_t end_offset = topic_name_len; - topic_name = liveliness::mangle_name(topic_name); - - if (topic_name_len > 0) { - if (topic_name[0] == '%') { - // Strip the leading '/' - start_offset = 1; - } - if (topic_name[end_offset - 1] == '%') { - // Strip the trailing '/' - end_offset -= 1; - } - } + std::string topic_nm(topic_name); + topic_nm = liveliness::mangle_name(topic_nm); return z_keyexpr_join( z_keyexpr(d.c_str()), - zc_keyexpr_from_slice(&topic_name[start_offset], end_offset - start_offset)); + z_keyexpr(topic_nm.c_str())); } //==============================================================================