From e0fe9ca02c9d9287f990f7855f87b957e6470f48 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Tue, 26 May 2020 16:56:05 -0300 Subject: [PATCH] Simplify namespacing utilities implementation. Signed-off-by: Michel Hidalgo --- .../src/namespace_prefix.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/namespace_prefix.cpp b/rmw_fastrtps_shared_cpp/src/namespace_prefix.cpp index 4945e8518..d02fd0d51 100644 --- a/rmw_fastrtps_shared_cpp/src/namespace_prefix.cpp +++ b/rmw_fastrtps_shared_cpp/src/namespace_prefix.cpp @@ -31,10 +31,8 @@ const std::vector _ros_prefixes = std::string _resolve_prefix(const std::string & name, const std::string & prefix) { - if (name.length() > prefix.length()) { - if (name.rfind(prefix, 0) == 0 && name.at(prefix.length()) == '/') { - return name.substr(prefix.length()); - } + if (name.rfind(prefix + "/", 0) == 0) { + return name.substr(prefix.length()); } return ""; } @@ -44,10 +42,8 @@ std::string _get_ros_prefix_if_exists(const std::string & topic_name) { for (const auto & prefix : _ros_prefixes) { - if (topic_name.length() > prefix.length()) { - if (topic_name.rfind(prefix, 0) == 0 && topic_name.at(prefix.length()) == '/') { - return prefix; - } + if (topic_name.rfind(prefix + "/", 0) == 0) { + return prefix; } } return ""; @@ -58,10 +54,8 @@ std::string _strip_ros_prefix_if_exists(const std::string & topic_name) { for (const auto & prefix : _ros_prefixes) { - if (topic_name.length() > prefix.length()) { - if (topic_name.rfind(prefix, 0) == 0 && topic_name.at(prefix.length()) == '/') { - return topic_name.substr(prefix.length()); - } + if (topic_name.rfind(prefix + "/", 0) == 0) { + return topic_name.substr(prefix.length()); } } return topic_name;