Пример #1
0
const CB::CString	CB::String::FromUTF8(const int8* szText, const uint32 uLength){
	if(szText == 0){
		throw CB::Exception::CNullPointerException(L"szText", 
			L"Cannot convert from null pointer.", CR_INFO());
	}
	if(uLength == 0){
		throw CB::Exception::CZeroLengthException(L"szText",
			L"Connot convert from zero length string.", CR_INFO());
	}

	try{
		CB::CString	strReturn;
#ifdef WIN32
		uint32 uLen = MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<const char*>(szText), uLength, 0, 0);

		strReturn.Resize(uLen);

		if(!MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<const char*>(szText), uLength, &strReturn[0], uLen)){
			DWORD dwError = GetLastError();
			throw CB::Exception::CInvalidVarValueException(L"dwError", CB::String::FromUInt32(dwError),
				L"Error while converting from UTF-8 to UTF-16.", CR_INFO());
		}
#else
#error ANSI - UNICODE only on win32 platform implemented.
#endif

		return strReturn;
	}
	catch(CB::Exception::CException& Exception){
		throw CB::Exception::CException(
			L"Error while converting from UTF-8 to UTF-16 string.", CR_INFO(), Exception);
	}
}