Skip to content
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

refactor: replace regex matching with find_last_of to split plugin name #271

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from

Conversation

ipa-fez
Copy link

@ipa-fez ipa-fez commented Feb 4, 2025

This gets rid of the regex based string splitting and just finds the appropriate substring using a delimiter directly.

I came across this because clang-19 raises some -Wmaybe-uninitialized warnings inside the regex code here.

Comment on lines +509 to +525
auto last_slash = lookup_name.find_last_of('/');
auto last_colon = lookup_name.find_last_of(':');
if (last_slash == std::string::npos && last_colon == std::string::npos) {
// no matches
return lookup_name;
}
if (last_slash == std::string::npos) {
// only colon matched
return lookup_name.substr(last_colon + 1);
}
if (last_colon == std::string::npos) {
// only slash matched
return lookup_name.substr(last_slash + 1);
}
// both matched, return shorter suffix
return lookup_name.substr(std::max(last_slash, last_colon) + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the PR!

Please add unit tests for ClassLoader<T>::getName so we can make sure the code works the same before and after the refactor
https://github.com/ros/pluginlib/blob/rolling/test/utest.cpp

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

I added some tests and the missing include. Let me know if I should add any additional test cases.

@ipa-fez ipa-fez force-pushed the refactor/no_regex branch 2 times, most recently from 3c0d559 to 1f8f369 Compare February 5, 2025 15:11
Signed-off-by: Felix Zeltner <28302109+ipa-fez@users.noreply.github.com>
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.

None yet

2 participants