Revision: 14637
Author: adrian.chadd
Date: Tue May  4 21:29:57 2010
Log: * Add strpbrk_n() - like strpbrk() but it takes a string length as an argument. * Add a couple of basic test-suite cases for strpbrk_n() - this is absolutely not comprehensive!


http://code.google.com/p/lusca-cache/source/detail?r=14637

Added:
 /branches/LUSCA_HEAD/test-suite/lib/util.c
Modified:
 /branches/LUSCA_HEAD/include/util.h
 /branches/LUSCA_HEAD/lib/util.c
 /branches/LUSCA_HEAD/test-suite/lib/build

=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/test-suite/lib/util.c  Tue May  4 21:29:57 2010
@@ -0,0 +1,26 @@
+#include "../../include/config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../include/util.h"
+
+
+void
+test_strpbrk_n(const char *foo)
+{
+       const char *w_space = " \t\n\r";
+       if (strpbrk_n(foo, strlen(foo), w_space))
+               printf("whitespace FOUND in '%s'\n", foo);
+       else
+               printf("whitespace NOT found in '%s'\n", foo);
+}
+
+int
+main(int argc, const char *argv[])
+{
+       test_strpbrk_n("abcdef");
+       test_strpbrk_n("abcdef ghi");
+       exit(0);
+}
=======================================
--- /branches/LUSCA_HEAD/include/util.h Sun Apr 18 00:01:22 2010
+++ /branches/LUSCA_HEAD/include/util.h Tue May  4 21:29:57 2010
@@ -165,5 +165,6 @@
 #endif

 extern long strtol_n(const char *nptr, int nlen, char **endptr, int base);
+extern const char * strpbrk_n(const char *s, int len, const char *charset);

 #endif /* SQUID_UTIL_H */
=======================================
--- /branches/LUSCA_HEAD/lib/util.c     Mon Apr 19 22:06:10 2010
+++ /branches/LUSCA_HEAD/lib/util.c     Tue May  4 21:29:57 2010
@@ -787,3 +787,17 @@

        return r;
 }
+
+const char *
+strpbrk_n(const char *s, int len, const char *charset)
+{
+       const char *c;
+
+       for (; len >= 0; s++, len--) {
+               for (c = charset; (*c) != '\0'; c++) {
+                       if ( (*s) == (*c) )
+                               return s;
+               }
+       }
+       return NULL;
+}
=======================================
--- /branches/LUSCA_HEAD/test-suite/lib/build   Thu Sep  4 05:59:29 2008
+++ /branches/LUSCA_HEAD/test-suite/lib/build   Tue May  4 21:29:57 2010
@@ -7,5 +7,7 @@
 rm rfc1035

 gcc ${CFLAGS}  rfc1035.c -o rfc1035 ${LDFLAGS} ${LIBS}
-
-./rfc1035
+gcc ${CFLAGS}  util.c -o util ${LDFLAGS} ${LIBS}
+
+# ./rfc1035
+./util

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to