Rewrote CString
This commit is contained in:
@@ -29,30 +29,110 @@
|
||||
* version.
|
||||
*/
|
||||
|
||||
#ifndef STRING_CUSTOM_H
|
||||
#define STRING_CUSTOM_H
|
||||
#ifndef _INCLUDE_CSTRING_H
|
||||
#define _INCLUDE_CSTRING_H
|
||||
|
||||
// *****************************************************
|
||||
// class String
|
||||
// *****************************************************
|
||||
|
||||
class String
|
||||
//by David "BAILOPAN" Anderson
|
||||
class CString
|
||||
{
|
||||
char* napis;
|
||||
short int len;
|
||||
|
||||
public:
|
||||
String();
|
||||
String( const char* n );
|
||||
~String();
|
||||
void set( const char* n );
|
||||
inline bool empty() const { return (len == 0); }
|
||||
inline const char* str() const { return napis ? napis : "(null)"; }
|
||||
inline short int size() const { return len; }
|
||||
void clear();
|
||||
CString() { v = NULL; mSize = 0; }
|
||||
~CString() { if (v) delete [] v; }
|
||||
|
||||
//added these for amxx
|
||||
CString(const char *src) { v = NULL; mSize = 0; assign(src); }
|
||||
CString(CString &src) { v = NULL; mSize = 0; assign(src.c_str()); }
|
||||
|
||||
const char *c_str() { return v?v:""; }
|
||||
const char *c_str() const { return v?v:""; }
|
||||
|
||||
void append(const char *t)
|
||||
{
|
||||
Grow(strlen(v) + strlen(t));
|
||||
strcat(v, t);
|
||||
}
|
||||
|
||||
void append(CString &d)
|
||||
{
|
||||
const char *t = d.c_str();
|
||||
Grow(strlen(v) + strlen(t));
|
||||
strcat(v, t);
|
||||
}
|
||||
|
||||
void assign(const char *d)
|
||||
{
|
||||
if (!d)
|
||||
{
|
||||
Grow(1);
|
||||
strcpy(v, "");
|
||||
return;
|
||||
}
|
||||
Grow(strlen(d));
|
||||
if (v)
|
||||
strcpy(v, d);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
if (v)
|
||||
delete [] v;
|
||||
v = NULL;
|
||||
mSize = 0;
|
||||
}
|
||||
|
||||
int compare (const char *d)
|
||||
{
|
||||
if (v) {
|
||||
if (d) {
|
||||
return strcmp(v, d);
|
||||
} else {
|
||||
return strlen(v);
|
||||
}
|
||||
} else {
|
||||
if (d) {
|
||||
return strlen(d);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Added this for amxx inclusion
|
||||
bool empty()
|
||||
{
|
||||
if (!v || !mSize)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int size()
|
||||
{
|
||||
if (!v)
|
||||
return 0;
|
||||
return strlen(v);
|
||||
}
|
||||
|
||||
private:
|
||||
void Grow(int d)
|
||||
{
|
||||
if (d<1)
|
||||
return;
|
||||
if (d > mSize)
|
||||
{
|
||||
char *t = new char[d+1];
|
||||
if (v) {
|
||||
strcpy(t, v);
|
||||
t[strlen(v)] = 0;
|
||||
delete [] v;
|
||||
}
|
||||
v = t;
|
||||
mSize = d;
|
||||
}
|
||||
}
|
||||
|
||||
char *v;
|
||||
int mSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif //_INCLUDE_CSTRING_H
|
Reference in New Issue
Block a user