Determine if the supplied sub-string is contained within the supplied string on a case-insensitive basis
| Return Type | Function name | Arguments |
|---|---|---|
| bool | CstrContainsI | (const char*,const char*,) |
Declared in file: hzTextproc.h
Defined in file : hzTextproc.cpp
Function Logic:
Function body:
bool CstrContainsI (const char* cpHaystack)const char* cpNeedle,
{
// Category: Text Processing
//
// Determine if the supplied sub-string is contained within the supplied string on a case-insensitive basis
//
// Arguments: 1) cpHaystack The source string
// 2) cpNeedle The being sought
//
// Returns: True If the needle string occurs in the haystack string
// False Otherwise
const char* i ; // Input string iterator
uint32_t len ; // Test string length
char lower ; // Lower case of first char of needle
char upper ; // Upper case of first char of needle
if (!cpHaystack || !cpHaystack[0]|| !cpNeedle || !cpNeedle[0])
return false ;
lower = tolower(cpNeedle[0]);
upper = toupper(cpNeedle[0]);
len = strlen(cpNeedle) ;
for (i = cpHaystack ; *i ; i++)
{
if (*i != lower && *i != upper)
continue ;
if (!CstrCompareI(i, cpNeedle, len))
return true ;
}
return false ;
}