File: strist.c

package info (click to toggle)
bibclean 2.11.4-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,212 kB
  • ctags: 1,545
  • sloc: ansic: 10,737; makefile: 817; perl: 66; sh: 40; awk: 27; sed: 6
file content (45 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download | duplicates (5)
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);
}