summaryrefslogtreecommitdiff
path: root/dlib
diff options
context:
space:
mode:
authorjcid <devnull@localhost>2008-04-06 18:58:30 +0200
committerjcid <devnull@localhost>2008-04-06 18:58:30 +0200
commit40334a7897e3b6f81ae957ae518e3e7afade32fe (patch)
treedb514b3dc7ba42eaa5fb65f00d3060fb6422118f /dlib
parent7650ae10e77d0058fe617ef670bad60349b45fed (diff)
- Added dStr_memmem() to dlib.
Diffstat (limited to 'dlib')
-rw-r--r--dlib/dlib.c20
-rw-r--r--dlib/dlib.h1
2 files changed, 21 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 ---------------------------------------------------------------------
*/
diff --git a/dlib/dlib.h b/dlib/dlib.h
index d86adc96..7bcac739 100644
--- a/dlib/dlib.h
+++ b/dlib/dlib.h
@@ -107,6 +107,7 @@ void dStr_vsprintf (Dstr *ds, const char *format, va_list argp);
void dStr_sprintf (Dstr *ds, const char *format, ...);
void dStr_sprintfa (Dstr *ds, const char *format, ...);
int dStr_cmp(Dstr *ds1, Dstr *ds2);
+char *dStr_memmem(Dstr *haystack, Dstr *needle);
/*
*-- dList --------------------------------------------------------------------