*improved locale processing.

This commit is contained in:
Wang Renxin 2016-08-04 09:31:29 +08:00
parent 0ccc23891a
commit d80578329c
3 changed files with 7 additions and 2 deletions

View File

@ -1,3 +1,6 @@
Aug. 4 2016
Improved locale processing
Jul. 26 2016 Jul. 26 2016
Fixed a multiple disposing bug with class member Fixed a multiple disposing bug with class member

View File

@ -15971,16 +15971,17 @@ _print:
_get_printer(s)(MB_REAL_FMT, val_ptr->data.float_point); _get_printer(s)(MB_REAL_FMT, val_ptr->data.float_point);
} else if(val_ptr->type == _DT_STRING) { } else if(val_ptr->type == _DT_STRING) {
#if defined MB_CP_VC && defined MB_ENABLE_UNICODE #if defined MB_CP_VC && defined MB_ENABLE_UNICODE
char* loc = setlocale(LC_ALL, "");
char* str = val_ptr->data.string ? val_ptr->data.string : MB_NULL_STRING; char* str = val_ptr->data.string ? val_ptr->data.string : MB_NULL_STRING;
_dynamic_buffer_t buf; _dynamic_buffer_t buf;
size_t lbuf = 0; size_t lbuf = 0;
_INIT_BUF(buf); _INIT_BUF(buf);
setlocale(LC_ALL, "");
while((lbuf = (size_t)mb_bytes_to_wchar(str, &_WCHAR_BUF_PTR(buf), _WCHARS_OF_BUF(buf))) > _WCHARS_OF_BUF(buf)) { while((lbuf = (size_t)mb_bytes_to_wchar(str, &_WCHAR_BUF_PTR(buf), _WCHARS_OF_BUF(buf))) > _WCHARS_OF_BUF(buf)) {
_RESIZE_WCHAR_BUF(buf, lbuf); _RESIZE_WCHAR_BUF(buf, lbuf);
} }
_get_printer(s)("%ls", _WCHAR_BUF_PTR(buf)); _get_printer(s)("%ls", _WCHAR_BUF_PTR(buf));
_DISPOSE_BUF(buf); _DISPOSE_BUF(buf);
setlocale(LC_ALL, loc);
#else /* MB_CP_VC && MB_ENABLE_UNICODE */ #else /* MB_CP_VC && MB_ENABLE_UNICODE */
_get_printer(s)(val_ptr->data.string ? val_ptr->data.string : MB_NULL_STRING); _get_printer(s)(val_ptr->data.string ? val_ptr->data.string : MB_NULL_STRING);
#endif /* MB_CP_VC && MB_ENABLE_UNICODE */ #endif /* MB_CP_VC && MB_ENABLE_UNICODE */

View File

@ -757,11 +757,12 @@ static void _list_one_line(bool_t nl, long l, const char* ln) {
#if defined MB_CP_VC && defined MB_ENABLE_UNICODE #if defined MB_CP_VC && defined MB_ENABLE_UNICODE
wchar_t wstr[16]; wchar_t wstr[16];
wchar_t* wstrp = wstr; wchar_t* wstrp = wstr;
setlocale(LC_ALL, ""); char* loc = setlocale(LC_ALL, "");
_bytes_to_wchar(ln, &wstrp, countof(wstr)); _bytes_to_wchar(ln, &wstrp, countof(wstr));
_printf(nl ? "%ld]%ls\n" : "%ld]%ls", l, wstrp); _printf(nl ? "%ld]%ls\n" : "%ld]%ls", l, wstrp);
if(wstrp != wstr) if(wstrp != wstr)
free(wstrp); free(wstrp);
setlocale(LC_ALL, loc);
#else /* MB_CP_VC && MB_ENABLE_UNICODE */ #else /* MB_CP_VC && MB_ENABLE_UNICODE */
_printf(nl ? "%ld]%s\n" : "%ld]%s", l, ln); _printf(nl ? "%ld]%s\n" : "%ld]%s", l, ln);
#endif /* MB_CP_VC && MB_ENABLE_UNICODE */ #endif /* MB_CP_VC && MB_ENABLE_UNICODE */