forked from brong/cyrus-imapd-legacy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstristr.c
81 lines (65 loc) · 1.83 KB
/
stristr.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* +++Date last modified: 05-Jul-1997 */
/* $Id: stristr.c,v 1.3 2002/05/25 19:57:47 leg Exp $ */
/*
** Designation: StriStr
**
** Call syntax: char *stristr(char *String, char *Pattern)
**
** Description: This function is an ANSI version of strstr() with
** case insensitivity.
**
** Return item: char *pointer if Pattern is found in String, else
** pointer to 0
**
** Rev History: 07/04/95 Bob Stout ANSI-fy
** 02/03/94 Fred Cole Original
**
** Hereby donated to public domain.
**
** Modified for use with libcyrus by Ken Murchison 06/01/00.
*/
#include <string.h>
#include <ctype.h>
#ifndef _AIX
typedef unsigned int uint;
#endif
#if defined(__cplusplus) && __cplusplus
extern "C" {
#endif
char *stristr(const char *String, const char *Pattern)
{
char *pptr, *sptr, *start;
uint slen, plen;
for (start = (char *)String,
pptr = (char *)Pattern,
slen = strlen(String),
plen = strlen(Pattern);
/* while string length not shorter than pattern length */
slen >= plen;
start++, slen--)
{
/* find start of pattern in string */
while (toupper(*start) != toupper(*Pattern))
{
start++;
slen--;
/* if pattern longer than string */
if (slen < plen)
return(NULL);
}
sptr = start;
pptr = (char *)Pattern;
while (toupper(*sptr) == toupper(*pptr))
{
sptr++;
pptr++;
/* if end of pattern then pattern was found */
if ('\0' == *pptr)
return (start);
}
}
return(NULL);
}
#if defined(__cplusplus) && __cplusplus
}
#endif