Skip to content

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

Merged

Conversation

Barry-Xu-2018
Copy link
Collaborator

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

Copy link
Collaborator

@fujitatomoya fujitatomoya left a 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)
Copy link
Collaborator

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);
}

Copy link
Collaborator Author

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.

@Barry-Xu-2018
Copy link
Collaborator Author

Barry-Xu-2018 commented Aug 16, 2025

Pulls: #2923
Gist: https://gist.githubusercontent.com/Barry-Xu-2018/b7bf6ed7353257611b68a0995631452b/raw/681d410f3620f863159edf38d443b4f928de1f0c/ros2_rolling.repos
BUILD args: --packages-above-and-dependencies rclcpp
TEST args: --packages-above rclcpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/16713

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Copy link
Contributor

@ahcorde ahcorde left a 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include <algorithm>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@Barry-Xu-2018
Copy link
Collaborator Author

Run CI again
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/16720

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde ahcorde merged commit 82696f6 into ros2:rolling Aug 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

extract_type_identifier() does not correctly handle invalid type strings starting with double slashes
4 participants