-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add StringArray_Find
family of functions
#36
Comments
Partly done, via cd96b37 I have added StringArray functions which mirror the I am leaving this issue open until we have a "Find substring anywhere inside stringarray" function implemented. |
I am thinking about how to implement this function... What prototype signature do you think that a There are ways to work around the lack of this function, depending on the use case:
char* found = StringArray_Find_F(strarr, match_func)
int found = StringArray_IndexOf_F(strarr, match_func)
char* found = (char*)StringArray_Reduce(strarr, match_func)
int found = (int)StringArray_Reduce(strarr, match_func)
//! Stores a position inside some string within a string array.
typedef struct strarr_pos
{
t_sint index; //!< index of the string in the string array
t_size offset; //!< offset of the char within the string
} s_strarr_pos;
s_strarr_pos StringArray_Find_Char (t_char const* const* strarr, t_char c);
s_strarr_pos StringArray_Find_Charset (t_char const* const* strarr, t_char const* cset);
s_strarr_pos StringArray_Find_String (t_char const* const* strarr, t_char const* str); Tell me what you think. |
The only way we have to find the substring is to get both the index in the array and the index in the string. So if we have both, we should probably return both and let the caller ignore whichever one he didn't care about (if any) Returning a struct is very good for clarity. It makes what the function returns very obvious, plus it is way cleaner (shorter) on the caller's side than say, returning results via out parameters (which is the only other way to return multiple values in c, right?) I'm all in for your prototypes defined in you Also I see the |
Add
StringArray_Find
andStringArray_Find_F
to be consistent with the existance ofPointerArray_Find
andPointerArray_Find_F
.The behavior of these
StringArray
functions should differ from thePointerArray
ones in the usage ofStringEquals
for equality comparison instead of simple pointer comparison.Another new function to search for a substring in any string of a
StringArray
would be nice to have as wellThe text was updated successfully, but these errors were encountered: