version 1.67, 2020/10/05 19:24:29 |
version 1.68, 2020/10/05 19:27:47 |
|
|
} |
} |
|
|
/* |
/* |
* Str_FindSubstring -- See if a string contains a particular substring. |
|
* |
|
* Input: |
|
* string String to search. |
|
* substring Substring to find in string. |
|
* |
|
* Results: If string contains substring, the return value is the location of |
|
* the first matching instance of substring in string. If string doesn't |
|
* contain substring, the return value is NULL. Matching is done on an exact |
|
* character-for-character basis with no wildcards or special characters. |
|
* |
|
* Side effects: None. |
|
*/ |
|
char * |
|
Str_FindSubstring(const char *string, const char *substring) |
|
{ |
|
const char *a, *b; |
|
|
|
/* |
|
* First scan quickly through the two strings looking for a single- |
|
* character match. When it's found, then compare the rest of the |
|
* substring. |
|
*/ |
|
|
|
for (b = substring; *string != 0; string++) { |
|
if (*string != *b) |
|
continue; |
|
a = string; |
|
for (;;) { |
|
if (*b == 0) |
|
return UNCONST(string); |
|
if (*a++ != *b++) |
|
break; |
|
} |
|
b = substring; |
|
} |
|
return NULL; |
|
} |
|
|
|
/* |
|
* Str_Match -- Test if a string matches a pattern like "*.[ch]". |
* Str_Match -- Test if a string matches a pattern like "*.[ch]". |
* |
* |
* XXX this function does not detect or report malformed patterns. |
* XXX this function does not detect or report malformed patterns. |