| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 | 
							- #include "string.h"
 
- #include <windows.h>
 
- #include <strsafe.h>
 
- using namespace tagz_;
 
- string::string()
 
- {
 
- 	data = 0;
 
- 	size = 0;
 
- 	used = 0;
 
- }
 
- void string::AddDBChar(LPTSTR c)
 
- {
 
- 	LPTSTR end = CharNext(c);
 
- 	while (c != end)
 
- 		AddChar(*c++);
 
- }
 
- void string::AddChar(TCHAR c)
 
- {
 
- 	if (!data)
 
- 	{
 
- 		size = 512;
 
- 		data = (LPTSTR)calloc(size, sizeof(TCHAR));
 
- 		if (!data) size = 0;
 
- 		used = 0;
 
- 	}
 
- 	else if (size == used)
 
- 	{
 
- 		size <<= 1;
 
- 		LPTSTR newData = (LPTSTR)realloc((LPTSTR)data, size * sizeof(TCHAR));
 
- 		if (!newData)
 
- 		{
 
- 			free(data);
 
- 			data = (LPTSTR)calloc(size, sizeof(TCHAR));
 
- 			if (!data) size = 0;
 
- 			used = 0;
 
- 		}
 
- 		else
 
- 		{
 
- 			data = newData;
 
- 			memset(data+used, 0, (size - used) * sizeof(TCHAR));
 
- 		}
 
- 	}
 
- 	if (data) 
 
- 		data[used++] = c;
 
- }
 
- void string::AddInt(int i)
 
- {
 
- 	TCHAR simpleInt[16] = {0};
 
- 	StringCchPrintf(simpleInt, 16, TEXT("%i"), i);
 
- 	AddString(simpleInt);
 
- }
 
- void string::AddString(LPCTSTR z)
 
- {
 
- 	while (z && *z)
 
- 	{
 
- 		AddChar(*z);
 
- 		z++;
 
- 	}
 
- }
 
- void string::AddString(string & s)
 
- {
 
- 	AddString(s.Peek());
 
- }
 
- string::~string()
 
- {
 
- 	if (data) free(data);
 
- }
 
- LPTSTR string::GetBuf()
 
- {
 
- 	if (!data)
 
- 		return NULL;
 
- 	LPTSTR r = (LPTSTR)realloc(data, (used + 1) * sizeof(TCHAR));
 
- 	if (!r)
 
- 	{
 
- 		free(data);
 
- 		data = 0;
 
- 		size = used + 1;
 
- 		r = (LPTSTR)calloc((used + 1), sizeof(TCHAR));
 
- 		if (!r) size = 0;
 
- 	}
 
- 	if (r) r[used] = 0;
 
- 	data = 0;
 
- 	return r;
 
- }
 
- TCHAR string::operator[](size_t i)
 
- {
 
- 	if (!data || i >= used) 
 
- 		return 0;
 
- 	else 
 
- 		return data[i];
 
- }
 
- size_t string::Len()
 
- {
 
- 	return data ? used : 0;
 
- }
 
- void string::Reset()
 
- {
 
- 	if (data)
 
- 	{
 
- 		free(data);
 
- 		data = 0;
 
- 	}
 
- 	size = 0;
 
- 	used = 0;
 
- }
 
- LPCTSTR string::Peek()
 
- {
 
- 	AddChar(0);
 
- 	used--;
 
- 	return data;
 
- }
 
 
  |