2004-06-29 12:09:53 +04:00
|
|
|
#ifndef _INCLUDE_CSTRING_H
|
|
|
|
#define _INCLUDE_CSTRING_H
|
|
|
|
|
|
|
|
//by David "BAILOPAN" Anderson
|
|
|
|
class CString
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CString() { v = NULL; mSize = 0; }
|
|
|
|
~CString() { if (v) delete [] v; }
|
|
|
|
|
|
|
|
const char *c_str() { 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));
|
2004-06-30 07:14:39 +04:00
|
|
|
if (v)
|
|
|
|
strcpy(v, d);
|
2004-06-29 12:09:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int size()
|
|
|
|
{
|
|
|
|
if (!v)
|
|
|
|
return 0;
|
|
|
|
return strlen(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Grow(int d)
|
|
|
|
{
|
2004-06-30 07:14:39 +04:00
|
|
|
if (d<1)
|
|
|
|
return;
|
2004-06-29 12:09:53 +04:00
|
|
|
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 //_INCLUDE_CSTRING_H
|