[ create a new paste ] login | about

Link: http://codepad.org/y60w7ej7    [ raw code | fork ]

C++, pasted on Nov 22:
#include <stdio.h>
#include <wchar.h>
#include <boost/shared_array.hpp>

class String
{
	boost::shared_array<wchar_t> _base;
public:
	String()
	{ 
		wchar_t *bs = new wchar_t[1];
		bs[0] = L'\0';
		_base = boost::shared_array<wchar_t>(bs);
	}

	String(const wchar_t *wArray)
	{
		int len = wcslen(wArray) + 1;
		wchar_t *bs = new wchar_t[len];
		wmemcpy_s(bs, len, wArray, len);
		_base = boost::shared_array<wchar_t>(bs);
	}

	String(String &copy){ this->_base = copy._base; }
	~String(){}
public:
	int Count() { return wcslen(_base.get()); }
	wchar_t* GetData() { return _base.get(); }
	String Substring(int index, int length) 
	{
		wchar_t* copyTo = new wchar_t[length + 1];
		wmemcpy_s(copyTo, length, _base.get() + index, length);
		copyTo[length] = L'\0';
		return String(copyTo);
	}
};

int main()
{
	setlocale(LC_ALL, "");
	String s = L"Stringクラスです。";
	wprintf(L"%s, count = %d, sizeof = %d\n", s.GetData(), s.Count(), sizeof(s));

	String substr = s.Substring(6, 3);
	wprintf(L"Substring: %s, count = %d\n", substr.GetData(), substr.Count());

	getchar();
	return 0;
}


Create a new paste based on this one


Comments: