changeset 163:9b036ecc40a4

- Added dStr_memmem() to dlib.
author jcid
date Sun, 06 Apr 2008 18:58:30 +0200
parents 7a0dad1cffe0
children 95be5cd3c392
files ChangeLog dlib/dlib.c dlib/dlib.h src/html.cc
diffstat 4 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Apr 04 00:23:21 2008 +0200
+++ b/ChangeLog	Sun Apr 06 18:58:30 2008 +0200
@@ -87,6 +87,7 @@
  - Fixed a bug in Html_parse_entity.
  - Fixed a bug in a_Url_cmp.
  - Fixed a bug in Cookies_parse_one. Set it to a single return potint too!
+ - Added dStr_memmem() to dlib.
    Patches: place
 +- Fixed a problem with locally-installed dpis.
  - Added code for optional image loading (nice interface) very advanced!
--- a/dlib/dlib.c	Fri Apr 04 00:23:21 2008 +0200
+++ b/dlib/dlib.c	Sun Apr 06 18:58:30 2008 +0200
@@ -415,6 +415,26 @@
 }
 
 /*
+ * 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 ---------------------------------------------------------------------
  */
 
--- a/dlib/dlib.h	Fri Apr 04 00:23:21 2008 +0200
+++ b/dlib/dlib.h	Sun Apr 06 18:58:30 2008 +0200
@@ -107,6 +107,7 @@
 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 --------------------------------------------------------------------
--- a/src/html.cc	Fri Apr 04 00:23:21 2008 +0200
+++ b/src/html.cc	Sun Apr 06 18:58:30 2008 +0200
@@ -4097,7 +4097,7 @@
             dStr_sprintf(boundary, "---------------------------%d%d%d",
                          rand(), rand(), rand());
             dStr_truncate(boundary, 70);
-            success = !strstr(DataStr->str, boundary->str);
+            success = (dStr_memmem(DataStr, boundary) == NULL);
          }
          dList_free(values);
          dStr_truncate(DataStr, 0);