Purpose: Compare two strings (cstr) on a case sensitive basis. This does not crash when given null arguments.
| Return Type | Function name | Arguments |
|---|---|---|
| int32_t | CstrCompare | (const char*,const char*,uint32_t,) |
Declared in file: hzTextproc.h
Defined in file : hzTextproc.cpp
Function Logic:
Function body:
int32_t CstrCompare (const char* pA)const char* pB, uint32_t nMaxlen,
{
// Category: Text Processing
//
// Purpose: Compare two strings (cstr) on a case sensitive basis. This does not crash when given null arguments.
//
// Arguments: 1) pA First string
// 2) pB Second string
// 3) nMaxlen Max length to compare (default 0 for no maximum)
//
// Returns: +1 If pA is lexically greater than pB within the specified length
// -1 If pA is lexically less than pB within the specified length
// 0 If pA and pB are equal within the specified length
_hzfunc("CstrCompare") ;
uint32_t nCount ; // Byte counter
if (!pA || !pA[0])
{
if (!pB) return 0;
if (!pB[0]) return 0;
return *pB ;
}
if (!pB || !pB[0])
return *pA ;
if (!nMaxlen)
for (; *pA && *pB && *pA == *pB ; pA++, pB++) ;
else
for (nCount = 0; nCount < nMaxlen && *pA && *pB && *pA == *pB ; nCount++, pA++, pB++) ;
return *pA - *pB ;
}