even better strings
This commit is contained in:
parent
2c024d2667
commit
9eb12e40e2
|
@ -12,6 +12,9 @@ int find_substrings(const char* haystack, const char* needle, size_t *num_substr
|
|||
|
||||
size_t sz_h = strlen(haystack);
|
||||
size_t sz_n = strlen(needle);
|
||||
if ((int)sz_h - (int)sz_n < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*num_substrings = 0;
|
||||
for (size_t i = 0; i <= sz_h - sz_n; ++i) {
|
||||
|
|
|
@ -285,6 +285,14 @@ void test_string() {
|
|||
subs = NULL;
|
||||
|
||||
find_substrings("test one two", "nope", &sub_sz, &subs);
|
||||
assert(sub_sz == 0);
|
||||
assert(subs == NULL);
|
||||
free(subs);
|
||||
subs = NULL;
|
||||
|
||||
find_substrings("123", "nopes", &sub_sz, &subs);
|
||||
assert(sub_sz == 0);
|
||||
assert(subs == NULL);
|
||||
free(subs);
|
||||
subs = NULL;
|
||||
|
||||
|
|
Loading…
Reference in New Issue