Normal sting type UTF-8 encoded format string
std::string Ofdewarserver::string_to_utf8 (const std::string & str)
{
int nwlen =:: MultiByteToWideChar (CP _ACP, 0, Str.c_str (),-1, NULL, 0);
wchar_t * Pwbuf = new Wchar_t[nwlen + 1];//must add 1, otherwise there will be tail
zeromemory (pwbuf, Nwlen * 2 + 2);
:: MultiByteToWideChar (C P_ACP, 0, Str.c_str (), Str.length (), Pwbuf, Nwlen);
int nlen =:: WideCharToMultiByte (Cp_utf8, 0, Pwbuf,-1, NULL, NULL, NULL, NULL);
char * PBuf = new Char[nlen + 1];
ZeroMemory (PBuf, Nlen + 1);
:: WideCharToMultiByte (Cp_utf8, 0, Pwbuf, Nwlen, PBuf, nlen, NULL, NULL);
std::string retstr (PBUF);
delete []pwbuf;
delete []pbuf;
Pwbuf = NULL;
PBuf = NULL;
return retstr;
}
//////////////////////////////////////////////////////////////////////////
UTF-8 encoded format string to normal sting type
std::string ofdewarserver::utf8_to_string (const std::string & str)
{
int nwlen = MultiByteToWideChar (CP_ UTF8, 0, Str.c_str (),-1, NULL, 0);
wchar_t * Pwbuf = new Wchar_t[nwlen + 1];//must add 1, otherwise there will be tail
memset (pwbuf, 0, Nwlen * 2 + 2);
MultiByteToWideChar (Cp_utf8, 0, Str.c_str (), Str.length (), Pwbuf, Nwlen);
int nlen = WideCharToMultiByte (CP_ACP, 0, Pwbuf,-1, NULL, NULL, NULL, NULL);
char * PBuf = new Char[nlen + 1];
memset (pBuf, 0, Nlen + 1);
WideCharToMultiByte (CP_ACP, 0, Pwbuf, Nwlen, PBuf, nlen, NULL, NULL);
std::string retstr = PBuf;
delete []pbuf;
delete []pwbuf;
PBuf = NULL;
Pwbuf = NULL;
return retstr;
}
//////////////////////////////////////////////////////////////////////////