diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index bd0be6a5..513da485 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -84,7 +84,7 @@ std::string strip_slashes(const char * const str) if (str[end] == '/') { --end; } - return ret.substr(start, end - start); + return ret.substr(start, end - start + 1); } //============================================================================== @@ -102,10 +102,13 @@ z_owned_keyexpr_t ros_topic_name_to_zenoh_key( const char * const topic_type, const char * const type_hash) { - const std::string keyexpr_str = std::to_string(domain_id) + "/" + - strip_slashes(topic_name) + "/" + - std::string(topic_type) + "/" + - std::string(type_hash); + std::string keyexpr_str = std::to_string(domain_id); + keyexpr_str += "/"; + keyexpr_str += strip_slashes(topic_name); + keyexpr_str += "/"; + keyexpr_str += topic_type; + keyexpr_str += "/"; + keyexpr_str += type_hash; return z_keyexpr_new(keyexpr_str.c_str()); }