Improve the function extract_type_identifier#2923
Conversation
Signed-off-by: Barry Xu <barry.xu@sony.com>
fujitatomoya
left a comment
There was a problem hiding this comment.
lgtm with minor suggestion.
| } | ||
| } | ||
|
|
||
| std::string string_trim(std::string_view str_v) |
There was a problem hiding this comment.
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.
Thanks. This way is more efficient.
Signed-off-by: Barry Xu <barry.xu@sony.com>
|
Pulls: #2923 |
ahcorde
left a comment
There was a problem hiding this comment.
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) { |
Signed-off-by: Barry Xu <barry.xu@sony.com>
|
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