-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Work/string search #2720
Work/string search #2720
Conversation
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.
Looks good! Just a couple of comments.
Should we add a wrapper function in Fw::StringBase
to call this function?
Did you consider using the libc |
@Joshua-Anderson I thought about it, but we prefer to use the "n" versions of string functions so they don't run off into space if the null terminator is corrupted. This is a home-grown version with an "n" adaptation, and the code is pretty small too. |
I second this. We should avoid using any string library functions that lack a buffer-bound argument. It looks like there is a |
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.
A few minor changes
FW_ASSERT((source_size - sub_size) <= std::numeric_limits<FwSignedSizeType>::max()); | ||
|
||
// Loop from zero to source_size - sub_size (inclusive) | ||
for (FwSizeType source_index = 0; |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
@@ -29,3 +30,45 @@ | |||
} | |||
return length; | |||
} | |||
|
|||
FwSignedSizeType Fw::StringUtils::substring_find(const CHAR* source_string, |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
@@ -29,3 +30,45 @@ | |||
} | |||
return length; | |||
} | |||
|
|||
FwSignedSizeType Fw::StringUtils::substring_find(const CHAR* source_string, |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
@@ -29,3 +30,45 @@ | |||
} | |||
return length; | |||
} | |||
|
|||
FwSignedSizeType Fw::StringUtils::substring_find(const CHAR* source_string, | |||
FwSizeType source_size, |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
|
||
FwSignedSizeType Fw::StringUtils::substring_find(const CHAR* source_string, | ||
FwSizeType source_size, | ||
const CHAR* sub_string, |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
FwSignedSizeType Fw::StringUtils::substring_find(const CHAR* source_string, | ||
FwSizeType source_size, | ||
const CHAR* sub_string, | ||
FwSizeType sub_size) { |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
Change Description
Added a function to
string_utils
to search for a substring in a stringRationale
Centralizes a feature that could be useful to many people.
Testing/Review Recommendations
Future Work
Calling this function will be added to
StringBase
as a helper.