-
Notifications
You must be signed in to change notification settings - Fork 466
Improve the function extract_type_identifier #2923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the function extract_type_identifier #2923
Conversation
Signed-off-by: Barry Xu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with minor suggestion.
@@ -73,6 +73,19 @@ const void * get_typesupport_handle_impl( | |||
} | |||
} | |||
|
|||
std::string string_trim(std::string_view str_v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about the following? instead of removing the space one by one? i believe it only scans the string twice, not once per whitespace character, and could be more readable and idiomatic.
std::string string_trim(std::string_view str_v) {
auto begin = std::find_if_not(str_v.begin(), str_v.end(), [](unsigned char ch) {
return std::isspace(ch);
});
auto end = std::find_if_not(str_v.rbegin(), str_v.rend(), [](unsigned char ch) {
return std::isspace(ch);
}).base();
if (begin >= end) return {};
return std::string(begin, end);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This way is more efficient.
Signed-off-by: Barry Xu <[email protected]>
Pulls: #2923 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think windows is failing because of this
// Trim leading and trailing whitespace from the string. | ||
std::string string_trim(std::string_view str_v) | ||
{ | ||
auto begin = std::find_if_not(str_v.begin(), str_v.end(), [](unsigned char ch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include <algorithm>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
Signed-off-by: Barry Xu <[email protected]>
Run CI again |
Description
Improve rclcpp::extract_type_identifier()
There are 2 issues reported in rosbag2 on extract_type_identifier().
ros2/rosbag2#2111
ros2/rosbag2#2113
Background:
The implementation of rosbag2::extract_type_identifier() has been moved to rclcpp::extract_type_identifier(). The rosbag2::extract_type_identifier() function will be removed in ros2/rosbag2#2017. Therefore, the fix should be made on the rclcpp side.
Fixes ros2/rosbag2#2111 and ros2/rosbag2#2113
Is this user-facing behavior change?
No
Did you use Generative AI?
No