remove unnecessary error check when converting ascii to unicode

This commit is contained in:
marynate 2014-02-21 19:48:04 +08:00
parent 0552b76475
commit f7cef6d617
1 changed files with 2 additions and 5 deletions

View File

@ -116,16 +116,13 @@ PCHAR*
} }
char* mb_to_utf8(const char* mbs) { char* mb_to_utf8(const char* mbs) {
int wlen = MultiByteToWideChar(CP_ACP,0,mbs,-1,NULL,0);
if (wlen < 0) int wlen = MultiByteToWideChar(CP_ACP,0,mbs,-1,NULL,0); // returns 0 if failed
wlen = 0;
wchar_t *wbuf = new wchar_t[wlen + 1]; wchar_t *wbuf = new wchar_t[wlen + 1];
MultiByteToWideChar(CP_ACP,0,mbs,-1,wbuf,wlen); MultiByteToWideChar(CP_ACP,0,mbs,-1,wbuf,wlen);
wbuf[wlen]=0; wbuf[wlen]=0;
int ulen = WideCharToMultiByte(CP_UTF8,0,wbuf,-1,NULL,0,NULL,NULL); int ulen = WideCharToMultiByte(CP_UTF8,0,wbuf,-1,NULL,0,NULL,NULL);
if (ulen < 0)
ulen = 0;
char * ubuf = new char[ulen + 1]; char * ubuf = new char[ulen + 1];
WideCharToMultiByte(CP_UTF8,0,wbuf,-1,ubuf,ulen,NULL,NULL); WideCharToMultiByte(CP_UTF8,0,wbuf,-1,ubuf,ulen,NULL,NULL);
ubuf[ulen] = 0; ubuf[ulen] = 0;