void CB::String::ToANSI(const CB::CString& strText, int8* szOutText, const uint32 uBufferLen){ if(strText.IsEmpty()){ throw CB::Exception::CZeroLengthException(L"strText", L"Cannot convert from zero length string.", CR_INFO()); } if(szOutText == 0){ throw CB::Exception::CNullPointerException(L"szOutText", L"Cannot convert to buffer with null pointer.", CR_INFO()); } if(uBufferLen < strText.GetLength()){ throw CB::Exception::CInvalidArgumentException(L"uLength", CB::String::FromUInt32(uBufferLen), L"Output buffer must have length at least equal as input string.", CR_INFO()); } try{ #ifdef WIN32 if(!WideCharToMultiByte(CP_ACP, 0, &strText[0], strText.GetLength(), reinterpret_cast<char*>(szOutText), uBufferLen, 0, 0)){ DWORD dwError = GetLastError(); throw CB::Exception::CInvalidVarValueException(L"dwError", CB::String::FromUInt32(dwError), L"Error while converting from UTF16 to ANSI.", CR_INFO()); } #else #error ANSI - UNICODE only on win32 platform implemented. #endif } catch(CB::Exception::CException& Exception){ throw CB::Exception::CException( L"Error while converting form UTF-16 to ANSII string.", CR_INFO(), Exception); } }
const uint32 CB::String::ToUTF8Count(const CB::CString& strText){ if(strText.IsEmpty()){ return 0; } #ifdef WIN32 return WideCharToMultiByte(CP_UTF8, 0, &strText[0], strText.GetLength(), 0, 0, 0, 0); #else #error ANSI - UNICODE only on win32 platform implemented. #endif }
const uint32 CB::String::ToANSICount(const CB::CString& strText){ return strText.GetLength(); }