1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
/* -*-C-*- strist.c */
/*-->strist*/
/**********************************************************************/
/****************************** strist ********************************/
/**********************************************************************/
#include <config.h>
#include "xctype.h"
#include "xstring.h"
RCSID("$Id: strist.c,v 1.1 1995/10/07 15:50:28 beebe Exp beebe $")
/* Return pointer to location of sub[] in s[], ignoring letter case,
else (char*)NULL. This is a simple implementation; a library version
should use a more sophisticated version (e.g. Boyer-Moore,
Knuth-Morris-Pratt, hardware search). */
char*
#if defined(HAVE_STDC)
stristr(
const char *s,
const char *sub
)
#else /* NOT defined(HAVE_STDC) */
stristr(s,sub)
const char *s;
const char *sub;
#endif /* defined(HAVE_STDC) */
{
size_t length;
length = (size_t)strlen(sub);
if (s == (const char*)NULL)
return ((char*)NULL);
if ((sub == (char*)NULL) || (*sub == '\0'))
return ((char*)s); /* NULL substring always found at start */
for (;*s;)
{
if (strnicmp(s,sub,length) == 0)
return ((char*)s);
++s;
}
return ((char*)NULL);
}
|