Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
142 lines
2.6 KiB
C++
142 lines
2.6 KiB
C++
// SimpleString.h: interface for the SimpleString class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#if !defined(AFX_SIMPLESTRING_H__F55EEDA2_FCE0_11D4_AD2B_0000E8EB4C69__INCLUDED_)
|
|
#define AFX_SIMPLESTRING_H__F55EEDA2_FCE0_11D4_AD2B_0000E8EB4C69__INCLUDED_
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif // _MSC_VER > 1000
|
|
|
|
|
|
#include "misc.h"
|
|
#include <string.h>
|
|
|
|
|
|
struct SimpleString
|
|
{
|
|
public:
|
|
SimpleString()
|
|
{
|
|
m_lAllocLength = 1;
|
|
m_szString = new char[1];
|
|
m_szString[0] = '\0';
|
|
}
|
|
|
|
SimpleString( const char* szString )
|
|
{
|
|
_ASSERT( szString );
|
|
|
|
m_lAllocLength = strlen( szString )+1;
|
|
|
|
m_szString = new char[m_lAllocLength];
|
|
strcpy( m_szString, szString );
|
|
}
|
|
|
|
SimpleString( const char* szString, int n )
|
|
{
|
|
_ASSERT( szString );
|
|
|
|
m_lAllocLength = n+1;
|
|
|
|
m_szString = new char[m_lAllocLength];
|
|
strncpy( m_szString, szString, n );
|
|
m_szString[n] = '\0';
|
|
}
|
|
|
|
SimpleString( const char* szString1, const char* szString2 )
|
|
{
|
|
_ASSERT( szString1 );
|
|
_ASSERT( szString2 );
|
|
|
|
m_lAllocLength = strlen(szString1) + strlen(szString2) + 1;
|
|
|
|
m_szString = new char[m_lAllocLength];
|
|
strcpy( m_szString, szString1 );
|
|
strcat( m_szString, szString2 );
|
|
}
|
|
|
|
~SimpleString()
|
|
{
|
|
SAFE_DELETEA( m_szString );
|
|
}
|
|
|
|
long Length()
|
|
{
|
|
return strlen(m_szString);
|
|
}
|
|
|
|
operator const char*() const
|
|
{
|
|
return m_szString;
|
|
}
|
|
|
|
void operator ()(const char* szString)
|
|
{
|
|
_ASSERT( szString );
|
|
|
|
if( (long)strlen(szString) < m_lAllocLength )
|
|
{
|
|
strcpy( m_szString, szString );
|
|
}
|
|
else
|
|
{
|
|
SAFE_DELETEA( m_szString );
|
|
m_lAllocLength = strlen(szString)+1;
|
|
|
|
m_szString = new char[m_lAllocLength];
|
|
strcpy( m_szString, szString );
|
|
}
|
|
}
|
|
|
|
void operator ()( const char* szString1, const char* szString2 )
|
|
{
|
|
_ASSERT( szString1 );
|
|
_ASSERT( szString2 );
|
|
|
|
if( (long)(strlen(szString1)+strlen(szString2)) < m_lAllocLength )
|
|
{
|
|
strcpy( m_szString, szString1 );
|
|
strcat( m_szString, szString2 );
|
|
}
|
|
else
|
|
{
|
|
SAFE_DELETEA( m_szString );
|
|
m_lAllocLength = strlen(szString1) + strlen(szString2) + 1;
|
|
|
|
m_szString = new char[m_lAllocLength];
|
|
strcpy( m_szString, szString1 );
|
|
strcat( m_szString, szString2 );
|
|
}
|
|
}
|
|
|
|
SimpleString& operator =(const char* szString)
|
|
{
|
|
_ASSERT( szString );
|
|
|
|
if( (long)strlen(szString) < m_lAllocLength )
|
|
{
|
|
strcpy( m_szString, szString );
|
|
}
|
|
else
|
|
{
|
|
SAFE_DELETEA( m_szString );
|
|
m_lAllocLength = strlen(szString)+1;
|
|
|
|
m_szString = new char[m_lAllocLength];
|
|
strcpy( m_szString, szString );
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
char* m_szString;
|
|
long m_lAllocLength;
|
|
};
|
|
|
|
#endif // !defined(AFX_SIMPLESTRING_H__F55EEDA2_FCE0_11D4_AD2B_0000E8EB4C69__INCLUDED_)
|