Mailing List Archive

[6854] cherokee/trunk/cherokee: Implements strncasestr() and strncasestrn() .
Revision: 6854
http://svn.cherokee-project.com/changeset/6854
Author: alo
Date: 2011-09-15 19:13:59 +0200 (Thu, 15 Sep 2011)
Log Message:
-----------
Implements strncasestr() and strncasestrn().

Modified Paths:
--------------
cherokee/trunk/cherokee/util.c
cherokee/trunk/cherokee/util.h

Modified: cherokee/trunk/cherokee/util.c
===================================================================
--- cherokee/trunk/cherokee/util.c 2011-09-15 17:13:48 UTC (rev 6853)
+++ cherokee/trunk/cherokee/util.c 2011-09-15 17:13:59 UTC (rev 6854)
@@ -298,7 +298,44 @@
}
#endif

+char *
+strncasestrn (const char *s, size_t slen, const char *find, size_t findlen)
+{
+ char c;
+ char sc;

+ if (unlikely (find == NULL) || (findlen == 0))
+ return s;
+
+ if (unlikely (*find == '\0'))
+ return s;
+
+ c = *find;
+ find++;
+ findlen--;
+
+ do {
+ do {
+ if (slen-- < 1 || (sc = *s++) == '\0')
+ return NULL;
+ } while (CHEROKEE_CHAR_TO_LOWER(sc) != CHEROKEE_CHAR_TO_LOWER(c));
+ if (findlen > slen) {
+ return NULL;
+ }
+ } while (strncasecmp (s, find, findlen) != 0);
+
+ s--;
+ return (char *)s;
+}
+
+char *
+strncasestr (const char *s, const char *find, size_t slen)
+{
+ return strncasestrn (s, slen, find, strlen(find));
+}
+
+
+
#ifndef HAVE_MALLOC
void *
rpl_malloc (size_t n)

Modified: cherokee/trunk/cherokee/util.h
===================================================================
--- cherokee/trunk/cherokee/util.h 2011-09-15 17:13:48 UTC (rev 6853)
+++ cherokee/trunk/cherokee/util.h 2011-09-15 17:13:59 UTC (rev 6854)
@@ -92,6 +92,9 @@
void *rpl_malloc (size_t n);
#endif

+char *strncasestr (const char *s, const char *find, size_t slen);
+char *strncasestrn (const char *s, size_t slen, const char *find, size_t findlen);
+
/* Constants
*/
extern const char hex2dec_tab[256];