#include "StdAfx.h"
#include "StrOps.h"
StrOps::StrOps(void)
{
}
StrOps::~StrOps(void)
{
}
int StrOps::StrCmp(const char* str1, const char* str2)
{
if ((str1 == NULL) && (str2 == NULL))
{
// two NULL str are eqivalent
return 1;
}
else if ((str1 == NULL) || (str2 == NULL))
{
// one NULL str fails
return 0;
}
int idx = 0;
while(1)
{
if (str1[idx] != str2[idx])
{
//charcters not equal
return 0;
}
if ((str1[idx] == '\0') || (str2[idx] == '\0'))
{
// if one is '\0' the othe must be as well or it would have failed the
// previous test for equality and retruned a false, so the strings must
// be equal
return 1;
}
idx++;
}
}
int StrOps::StrLen(const char* str)
{
int len = 0;
while(str[len] != '\0')
{
len++;
}
return len;
}
char* StrOps::StrDup(const char* str)
{
int len = StrLen(str);
char* val = new char[len+1];
for (int idx = 0; idx < len; idx++)
{
val[idx] = str[idx];
}
val[len] = '\0';
return val;
}