All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
strcasestr.cpp File Reference
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

Go to the source code of this file.

Functions

char * strcasestr (const char *haystack, const char *needle)
 Locatea substring into a string, ignoring case. More...
 

Function Documentation

char* strcasestr ( const char *  haystack,
const char *  needle 
)

Locatea substring into a string, ignoring case.

Parameters
haystackThe string to search in.
needleThe substring to find.
Returns

This function locates the string needle into the string haystack, ignoring the case of the characters. It returns apointer to the beginning of the substring, or NULL if the substring is not found. If haystack or needle are NULL, this function returns NULL.

Conformity: Non applicable.

Supported OS: Windows XP, Windows CE

Definition at line 43 of file strcasestr.cpp.

43  {
44  size_t length_needle;
45  size_t length_haystack;
46  size_t i;
47 
48  if (!haystack || !needle)
49  return NULL;
50 
51  length_needle = strlen(needle);
52  length_haystack = strlen(haystack) - length_needle + 1;
53 
54  for (i = 0; i < length_haystack; i++)
55  {
56  size_t j;
57 
58  for (j = 0; j < length_needle; j++)
59  {
60  unsigned char c1;
61  unsigned char c2;
62 
63  c1 = haystack[i+j];
64  c2 = needle[j];
65  if (toupper(c1) != toupper(c2))
66  goto next;
67  }
68  return (char *) haystack + i;
69  next:
70  ;
71  }
72 
73  return NULL;
74 }
#define NULL
Definition: host.h:144