Skip to content

Commit

Permalink
Simplify namespacing utilities implementation.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic committed May 26, 2020
1 parent 2a0acb3 commit e0fe9ca
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions rmw_fastrtps_shared_cpp/src/namespace_prefix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ const std::vector<std::string> _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 "";
}
Expand All @@ -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 "";
Expand All @@ -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;
Expand Down

0 comments on commit e0fe9ca

Please sign in to comment.