Skip to content

Improve the function extract_type_identifier#2923

Merged
ahcorde merged 3 commits intoros2:rollingfrom
Barry-Xu-2018:revew/topic-improve-extract_type_identifier
Aug 18, 2025
Merged

Improve the function extract_type_identifier#2923
ahcorde merged 3 commits intoros2:rollingfrom
Barry-Xu-2018:revew/topic-improve-extract_type_identifier

Conversation

@Barry-Xu-2018
Copy link
Copy Markdown
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

Signed-off-by: Barry Xu <barry.xu@sony.com>
Copy link
Copy Markdown
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.

}
}

std::string string_trim(std::string_view str_v)
Copy link
Copy Markdown
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
Copy Markdown
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.

Signed-off-by: Barry Xu <barry.xu@sony.com>
@Barry-Xu-2018
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator Author

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 <barry.xu@sony.com>
@Barry-Xu-2018
Copy link
Copy Markdown
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