utf 8 - Why use MultiByteToWideChar and WideCharToMultiByte at the same time? -
i saw code this: why use multibytetowidechar , widechartomultibyte @ same time?
char szline[max_length_string] = {0} ... //some operate szline char *szutf8string; wchar_t *szunicodestring; int size; int room; size = strlen(szline)+1; room = multibytetowidechar(cp_acp, 0, szline, -1, null, 0); szunicodestring = (wchar_t*) malloc((sizeof(wchar_t))*room); multibytetowidechar(cp_acp, 0, szline, -1, szunicodestring, room); room = widechartomultibyte(cp_utf8, 0, szunicodestring, -1, null, 0, null, null); szutf8string = (char*) malloc(room); widechartomultibyte(cp_utf8, 0, szunicodestring, -1, szutf8string, room, null, null);
this code fragment first converts string multibyte representation using system default code page unicode, converts utf-8 multibyte representation. thus, converts text in default code page utf-8 representation.
the code fragile, in assumes utf-8 version double in size (this works of time, worse case single byte in default code page may map 4 bytes in utf-8).
Comments
Post a Comment