1515
1616#include " rclcpp/typesupport_helpers.hpp"
1717
18+ #include < algorithm>
1819#include < functional>
1920#include < memory>
2021#include < sstream>
@@ -73,6 +74,21 @@ const void * get_typesupport_handle_impl(
7374 }
7475}
7576
77+ // Trim leading and trailing whitespace from the string.
78+ std::string string_trim (std::string_view str_v)
79+ {
80+ auto begin = std::find_if_not (str_v.begin (), str_v.end (), [](unsigned char ch) {
81+ return std::isspace (ch);
82+ });
83+ auto end = std::find_if_not (str_v.rbegin (), str_v.rend (), [](unsigned char ch) {
84+ return std::isspace (ch);
85+ }).base ();
86+ if (begin >= end) {
87+ return {};
88+ }
89+ return std::string (begin, end);
90+ }
91+
7692} // anonymous namespace
7793
7894std::tuple<std::string, std::string, std::string>
@@ -82,6 +98,7 @@ extract_type_identifier(const std::string & full_type)
8298 auto sep_position_back = full_type.find_last_of (type_separator);
8399 auto sep_position_front = full_type.find_first_of (type_separator);
84100 if (sep_position_back == std::string::npos ||
101+ sep_position_front == 0 ||
85102 sep_position_back == 0 ||
86103 sep_position_back == full_type.length () - 1 )
87104 {
@@ -97,7 +114,8 @@ extract_type_identifier(const std::string & full_type)
97114 }
98115 std::string type_name = full_type.substr (sep_position_back + 1 );
99116
100- return std::make_tuple (package_name, middle_module, type_name);
117+ return std::make_tuple (
118+ string_trim (package_name), string_trim (middle_module), string_trim (type_name));
101119}
102120
103121std::string get_typesupport_library_path (
0 commit comments