@@ -34,25 +34,21 @@ _demangle_if_ros_topic(const std::string & topic_name)
3434std::string
3535_demangle_if_ros_type (const std::string & dds_type_string)
3636{
37- std::regex dds_namespace_pattern ( " [^:]+((::.+::)+ dds_::).* " ) ;
38- std::smatch match ;
37+ std::string substring = " dds_::" ;
38+ size_t substring_position = dds_type_string. find (substring) ;
3939 if (
4040 dds_type_string[dds_type_string.size () - 1 ] != ' _' ||
41- ! std::regex_match (dds_type_string, match, dds_namespace_pattern) )
41+ substring_position == std::string::npos )
4242 {
4343 // not a ROS type
4444 return dds_type_string;
4545 }
4646
47- // The first submatch is the whole string, the second is the outer parenthesized expression
48- // and the third is the inner parenthesized expression
49- assert (3u == match.size ());
50- std::string substring = match[1 ].str ();
51- size_t substring_position = dds_type_string.find (substring);
52- std::string pkg = dds_type_string.substr (0 , substring_position);
47+ std::string type_namespace = dds_type_string.substr (0 , substring_position);
48+ type_namespace = std::regex_replace (type_namespace, std::regex (" ::" ), " /" );
5349 size_t start = substring_position + substring.size ();
5450 std::string type_name = dds_type_string.substr (start, dds_type_string.length () - 1 - start);
55- return pkg + " / " + type_name;
51+ return type_namespace + type_name;
5652}
5753
5854// / Return the service name for a given topic if it is part of one, else "".
@@ -114,16 +110,12 @@ _demangle_service_from_topic(const std::string & topic_name)
114110std::string
115111_demangle_service_type_only (const std::string & dds_type_name)
116112{
117- std::regex dds_namespace_pattern ( " .*(::.*:: dds_::).* " ) ;
118- std::smatch match ;
119- if (! std::regex_match (dds_type_name, match, dds_namespace_pattern) ) {
113+ std::string ns_substring = " dds_::" ;
114+ size_t ns_substring_position = dds_type_name. find (ns_substring) ;
115+ if (std::string::npos == ns_substring_position ) {
120116 // not a ROS service type
121117 return " " ;
122118 }
123- // The first submatch is the whole string and the second is the parenthesized expression
124- assert (2u == match.size ());
125- std::string ns_substring = match[1 ].str ();
126- size_t ns_substring_position = dds_type_name.find (ns_substring);
127119 auto suffixes = {
128120 std::string (" _Response_" ),
129121 std::string (" _Request_" ),
@@ -135,7 +127,7 @@ _demangle_service_type_only(const std::string & dds_type_name)
135127 if (suffix_position != std::string::npos) {
136128 if (dds_type_name.length () - suffix_position - suffix.length () != 0 ) {
137129 RCUTILS_LOG_WARN_NAMED (" rmw_fastrtps_shared_cpp" ,
138- " service type contains '::*:: dds_::' and a suffix, but not at the end"
130+ " service type contains 'dds_::' and a suffix, but not at the end"
139131 " , report this: '%s'" , dds_type_name.c_str ());
140132 continue ;
141133 }
@@ -145,13 +137,15 @@ _demangle_service_type_only(const std::string & dds_type_name)
145137 }
146138 if (std::string::npos == suffix_position) {
147139 RCUTILS_LOG_WARN_NAMED (" rmw_fastrtps_shared_cpp" ,
148- " service type contains '::*:: dds_::' but does not have a suffix"
140+ " service type contains 'dds_::' but does not have a suffix"
149141 " , report this: '%s'" , dds_type_name.c_str ());
150142 return " " ;
151143 }
152- // everything checks out, reformat it from '<pkg>::srv::dds_::<type><suffix>' to '<pkg>/<type>'
153- std::string pkg = dds_type_name.substr (0 , ns_substring_position);
144+ // everything checks out, reformat it from '[type_namespace::]dds_::<type><suffix>'
145+ // to '[type_namespace/]<type>'
146+ std::string type_namespace = dds_type_name.substr (0 , ns_substring_position);
147+ type_namespace = std::regex_replace (type_namespace, std::regex (" ::" ), " /" );
154148 size_t start = ns_substring_position + ns_substring.length ();
155149 std::string type_name = dds_type_name.substr (start, suffix_position - start);
156- return pkg + " / " + type_name;
150+ return type_namespace + type_name;
157151}
0 commit comments