Hmm. Maybe I should have a play around with the std::string stuff and see what it can do.
Daved: Heres the code for the functions:
Code:
char* String::GetLeft(Uint16 chars)
{
if(chars >= size) return str_ptr;
if(tmp_ptr != NULL) delete []tmp_ptr;
tmp_ptr = new char[chars+1];
char *src = str_ptr;
char *dst = tmp_ptr;
for(int i=0; i<chars; i++)
{
*dst = *src;
src++; dst++;
}
++*dst='\0';
return tmp_ptr;
}
char* String::GetRight(Uint16 chars)
{
if(chars >= size) return str_ptr;
if(tmp_ptr != NULL) delete []tmp_ptr;
tmp_ptr = new char[chars+1];
char *src = str_ptr;
char *dst = tmp_ptr;
int start = size-chars-1;
for(int i=0; i<start; i++, src++);
while(*src)
{
*dst = *src;
src++; dst++;
}
++*dst='\0';
return tmp_ptr;
}
char* String::GetMid(Uint16 start, Uint16 chars)
{
if(chars >= size) return str_ptr;
if(tmp_ptr != NULL) delete []tmp_ptr;
tmp_ptr = new char[chars+1];
char *src = str_ptr;
char *dst = tmp_ptr;
for(int i=1; i<start; i++, src++);
for(int i=0; i<chars; i++, src++, dst++) *dst = *src;
++*dst='\0';
return tmp_ptr;
}
And heres the class definition:
Code:
class String
{
public:
String();
String(const char*);
~String(){}
void Add(char*);
void Set(char*);
void Print(Uint8);
char* Get();
char* GetLeft(Uint16);
char* GetRight(Uint16);
char* GetMid(Uint16, Uint16);
int Len();
int Sub(char*, bool);
void ToUpper();
void ToLower();
bool Replace(char*, char*, bool);
void ReplaceAll(char*, char*, bool);
bool ChopLeft(Uint16);
bool ChopRight(Uint16);
bool ChopMid(Uint16, Uint16);
char GetChar(Uint16);
void Insert(char*, Uint16);
void Reverse();
void Split(char); //Splits string at each occurence of a character
void Spilt(Uint16); //Splits string at index
private:
Uint16 size;
char *str_ptr;
char *tmp_ptr;
};