diff options
Diffstat (limited to 'dlib/dlib.c')
-rw-r--r-- | dlib/dlib.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/dlib/dlib.c b/dlib/dlib.c index 78fa951d..862e642f 100644 --- a/dlib/dlib.c +++ b/dlib/dlib.c @@ -415,6 +415,26 @@ int dStr_cmp(Dstr *ds1, Dstr *ds2) } /* + * Return a pointer to the first occurrence of needle in haystack. + */ +char *dStr_memmem(Dstr *haystack, Dstr *needle) +{ + int i; + + if (needle && haystack) { + if (needle->len == 0) + return haystack->str; + + for (i = 0; i <= (haystack->len - needle->len); i++) { + if (haystack->str[i] == needle->str[0] && + !memcmp(haystack->str + i, needle->str, needle->len)) + return haystack->str + i; + } + } + return NULL; +} + +/* *- dList --------------------------------------------------------------------- */ |