Last active
September 1, 2021 11:34
-
-
Save Quackward/49b0037ddbc6a23f6b91daff95a62227 to your computer and use it in GitHub Desktop.
Revisions
-
Quackward revised this gist
Sep 1, 2021 . 1 changed file with 30 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ // [email protected] \(v ` >`)_v // returns index of first `searchStrs` we found, or `searchCount` if none was found // str string we are searching through // searchStrs array of sub-strings we are looking for // searchCount the count of sub-strings we are looking for // outStartOfArg if not NULL, fills this with pointer to first char in found search, or NULL if none found // outEndOfArg if not NULL, fills this with pointer to first char AFTER found search, or NULL if none found uint32 findFirstSubStr(const char * str, const char ** searchStrs, uint32 searchCount, const char ** outStartOfArg, const char ** outEndOfArg) { @@ -29,4 +29,31 @@ uint32 findFirstSubStr(const char * str, const char ** searchStrs, uint32 search if(outStartOfArg) *outStartOfArg = NULL; if(outEndOfArg) *outEndOfArg = NULL; return searchCount; } // same as `findFirstSubStr()` but case insensitive uint32 findFirstSubStr_caseless(const char * str, const char ** searchStrs, uint32 searchCount, const char ** outStartOfArg, const char ** outEndOfArg) { if (str && searchStrs && searchCount) { while (*str) { for (uint32 n = 0; n < searchCount; ++n) { if (searchStrs[n] && tolower(*str) == tolower(searchStrs[n][0])) { const char * token = searchStrs[n]+1; const char * strSub = str+1; while (*token && tolower(*token) == tolower(*strSub)) { ++token; ++strSub; } if (*token == 0) { if(outStartOfArg) *outStartOfArg = str; if(outEndOfArg) *outEndOfArg = strSub; return n; } } } ++str; } } if(outStartOfArg) *outStartOfArg = NULL; if(outEndOfArg) *outEndOfArg = NULL; return searchCount; } -
Quackward created this gist
Sep 1, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ // [email protected] \(v ` >`)_v // returns index of first `searchStr` we found, or `searchCount` if none was found // str string we are searching through // searchStrs array of strings we are looking for // searchCount the number of strings we are looking for // outStartOfArg if not NULL, fills this with pointer to first char in found search, or NULL if none found // outEndOfArg if not NULL, fills this with pointer to first char AFTER found search, or NULL if none found uint32 findFirstSubStr(const char * str, const char ** searchStrs, uint32 searchCount, const char ** outStartOfArg, const char ** outEndOfArg) { if (str && searchStrs && searchCount) { while (*str) { for (uint32 n = 0; n < searchCount; ++n) { if (searchStrs[n] && *str == searchStrs[n][0]) { const char * token = searchStrs[n]+1; const char * strSub = str+1; while (*token && *token == *strSub) { ++token; ++strSub; } if (*token == 0) { if(outStartOfArg) *outStartOfArg = str; if(outEndOfArg) *outEndOfArg = strSub; return n; } } } ++str; } } if(outStartOfArg) *outStartOfArg = NULL; if(outEndOfArg) *outEndOfArg = NULL; return searchCount; }