#ifndef __TEXTCONTAINER__
#define __TEXTCONTAINER__

#include <string.h>
#include "ChipmonkTypes.h"

static int wstrlen(const WCHAR *str) {
	int i = 0;
	for(; str[i] != 0; ++i);
	return i;
}

struct TextContainer{
	WCHAR *m_pData;
	int m_nSize;
	WCHAR *GetData(){return m_pData;}
	void Copy(const WCHAR *str){
		int nSize = wstrlen(str);
		SetSize(nSize + 1);
		memcpy(m_pData, str, nSize);
		m_pData[nSize] = 0;
	}

	void Copy(const TextContainer & tc){
		Copy(tc.m_pData);
	}

	void SetSize(int nSize){
		if(nSize > m_nSize){
			if(m_pData){
				delete [] m_pData;
			}
			m_pData = new WCHAR [m_nSize = nSize];
			*m_pData = '\0';
		}
	}
	
	BOOL IsEmpty()const{
		if(m_pData){
			return *m_pData == '\0';
		}
		return TRUE;
	}

	TextContainer(int nSize = 1024){
		m_nSize = 0;
		m_pData = NULL;
		SetSize(nSize);
	}
	
	~TextContainer(){	if(m_pData){
				delete [] m_pData;
			}
	}
};

#endif
