home *** CD-ROM | disk | FTP | other *** search
- /*
- ** 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: 02/03/94 Fred Cole
- **
- ** Hereby donated to public domain.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
- typedef unsigned int uint;
-
- char *stristr(char *String, char *Pattern)
- {
- char *pptr, *sptr, *start;
- uint slen, plen;
-
- for (start = String,
- pptr = 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((char*)0);
- }
-
- sptr = start;
- pptr = Pattern;
-
- while (toupper(*sptr) == toupper(*pptr))
- {
- sptr++;
- pptr++;
-
- /* if end of pattern then pattern was found */
-
- if ('\0' == *pptr)
- return (start);
- }
- }
- return((char*)0);
- }
-
- #ifdef TEST
-
- int main(void)
- {
- char buffer[80] = "heLLo, HELLO, hello, hELLo";
- char *sptr = buffer;
-
- while (0 != (sptr = StriStr(sptr, "hello")))
- printf("Found %5.5s!\n", sptr++);
-
- return(0);
- }
-
- #endif
-