Closed timcanham closed 1 month ago
Did you consider using the libc strstr
function? It does have a prereq on the strings being null terminated (rather than providing a length argument) but if the plan is to use it with StringBase I think that may be reasonable assumption.
@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 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.
I second this. We should avoid using any string library functions that lack a buffer-bound argument. It looks like there is a strnstr
function, but it is BSD-specific, so it won't work on general POSIX.
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.