diff --git a/core/src/introspection.cpp b/core/src/introspection.cpp index 588b9e99..0148edbc 100644 --- a/core/src/introspection.cpp +++ b/core/src/introspection.cpp @@ -49,6 +49,12 @@ #include #include +namespace ros { +namespace names { +bool isValidCharInName(char c); // unfortunately this is not declared in ros/names.h +} // namespace names +} // namespace ros + namespace moveit { namespace task_constructor { @@ -57,8 +63,10 @@ std::string getTaskId(const TaskPrivate* task) { std::ostringstream oss; char our_hostname[256] = { 0 }; gethostname(our_hostname, sizeof(our_hostname) - 1); - // Hostname could have `-` as a character but this is an invalid character in ROS so we replace it with `_` - std::replace(std::begin(our_hostname), std::end(our_hostname), '-', '_'); + // Replace all invalid ROS-name chars with an underscore + std::replace_if( + our_hostname, our_hostname + strlen(our_hostname), + [](const char ch) { return !ros::names::isValidCharInName(ch); }, '_'); oss << our_hostname << "_" << getpid() << "_" << reinterpret_cast(task); return oss.str(); }