diff --git a/core/my_basic.c b/core/my_basic.c index 8f6d890..5ac1154 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -32,7 +32,9 @@ #include "my_basic.h" #ifdef MB_CP_VC # include +# include # include +# include #else /* MB_CP_VC */ # include #endif /* MB_CP_VC */ @@ -1193,6 +1195,10 @@ static char* mb_strupr(char* s); static bool_t mb_is_little_endian(void); +#if defined MB_CP_VC && defined MB_ENABLE_UNICODE +static bool_t mb_bytes_to_wchar(const char* sz, wchar_t** out, size_t size); +#endif /* MB_CP_VC && MB_ENABLE_UNICODE */ + /** Unicode handling */ static int mb_uu_getbom(const char** ch); @@ -2953,6 +2959,18 @@ static bool_t mb_is_little_endian(void) { return ((char*)&i)[0] == 1; } +#if defined MB_CP_VC && defined MB_ENABLE_UNICODE +/* Map a UTF8 character string to a UTF16 (wide character) string */ +static bool_t mb_bytes_to_wchar(const char* sz, wchar_t** out, size_t size) { + int min_size = MultiByteToWideChar(CP_UTF8, 0, sz, -1, NULL, 0); + if((int)size < min_size) + *out = (wchar_t*)mb_malloc(sizeof(wchar_t) * min_size); + MultiByteToWideChar(CP_UTF8, 0, sz, -1, *out, min_size); + + return true; +} +#endif /* MB_CP_VC && MB_ENABLE_UNICODE */ + /** Unicode handling */ /* Determine whether a string begins with a BOM, and ignore it */ @@ -15540,7 +15558,18 @@ _print: } else if(val_ptr->type == _DT_REAL) { _get_printer(s)(MB_REAL_FMT, val_ptr->data.float_point); } else if(val_ptr->type == _DT_STRING) { +#if defined MB_CP_VC && defined MB_ENABLE_UNICODE + char* str = val_ptr->data.string ? val_ptr->data.string : MB_NULL_STRING; + wchar_t wstr[16]; + wchar_t* wstrp = wstr; + setlocale(LC_ALL, ""); + mb_bytes_to_wchar(str, &wstrp, countof(wstr)); + _get_printer(s)("%ls", wstrp); + if(wstrp != wstr) + mb_free(wstrp); +#else /* MB_CP_VC && MB_ENABLE_UNICODE */ _get_printer(s)(val_ptr->data.string ? val_ptr->data.string : MB_NULL_STRING); +#endif /* MB_CP_VC && MB_ENABLE_UNICODE */ if(!val_ptr->ref && val_ptr->data.string) { safe_free(val_ptr->data.string); }