StrOps.cpp #3

  • //
  • guest/
  • eskopljak/
  • p4api.net/
  • main/
  • p4bridgeStressTest/
  • StrOps.cpp
  • View
  • Commits
  • Open Download .zip Download (983 B)
#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;
}
# Change User Description Committed
#3 28480 eskopljak submit
#2 28479 eskopljak submit
#1 28441 eskopljak Merging using p4api.net_branch
//guest/perforce_software/p4api-net/main/p4bridgeStressTest/StrOps.cpp
#1 19044 Norman Morse Update workshop source from Perforce internal.
2016.1 release of P4API.NET