Commit ec3d77bc authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Vitaly Lipatov

wine/debug.h: Make wine_dbgstr_wn use UTF-8 for output. (eterbug #14134)

parent 5edc3adb
......@@ -946,6 +946,19 @@ NTSTATUS WINAPI RtlUnicodeToUTF8N( char *dst, DWORD dstlen, DWORD *reslen, const
}
/******************************************************************
* ntdll_wcstoumbs
*/
int ntdll_wcstoumbs( const WCHAR *src, DWORD srclen, char *dst, DWORD dstlen, BOOL strict )
{
DWORD reslen;
/* Assume UTF-8 is always the target encoding */
RtlUnicodeToUTF8N( dst, dstlen, &reslen, src, srclen * sizeof(WCHAR) );
return reslen;
}
/******************************************************************************
* RtlIsNormalizedString (NTDLL.@)
*/
......
......@@ -223,6 +223,15 @@ static inline int __wine_dbg_cdecl wine_dbg_log( enum __wine_debug_class cls,
return ret;
}
#ifdef _NTSYSTEM_
extern int ntdll_wcstoumbs(const WCHAR *,DWORD,char *,DWORD,BOOL);
#else
#ifndef NTSTATUS
typedef LONG NTSTATUS;
#endif
NTSYSAPI NTSTATUS WINAPI RtlMultiByteToUnicodeN(WCHAR *,DWORD,DWORD*,const char *,DWORD);
NTSYSAPI NTSTATUS WINAPI RtlUnicodeToUTF8N(LPSTR,DWORD,DWORD*,LPCWSTR,DWORD);
#endif
static inline const char *wine_dbgstr_an( const char *str, int n )
{
static const char hex[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
......@@ -246,12 +255,27 @@ static inline const char *wine_dbgstr_an( const char *str, int n )
case '"': *dst++ = '\\'; *dst++ = '"'; break;
case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
default:
if (c < ' ' || c >= 127)
if (c < ' ')
{
*dst++ = '\\';
*dst++ = 'x';
*dst++ = hex[(c >> 4) & 0x0f];
*dst++ = hex[c & 0x0f];
}
else if (c >= 127)
{
#if defined _NTSYSTEM_ || defined WINE_UNIX_LIB
*dst++ = '\\';
*dst++ = 'x';
*dst++ = hex[(c >> 4) & 0x0f];
*dst++ = hex[c & 0x0f];
#else
WCHAR wc;
DWORD reslen;
RtlMultiByteToUnicodeN(&wc, sizeof(wc), &reslen, (const char *)&c, 1);
RtlUnicodeToUTF8N(dst, 4, &reslen, &wc, sizeof(wc));
dst += reslen;
#endif
}
else *dst++ = c;
}
......@@ -291,7 +315,7 @@ static inline const char *wine_dbgstr_wn( const WCHAR *str, int n )
case '"': *dst++ = '\\'; *dst++ = '"'; break;
case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
default:
if (c < ' ' || c >= 127)
if (c < ' ')
{
*dst++ = '\\';
*dst++ = hex[(c >> 12) & 0x0f];
......@@ -299,6 +323,17 @@ static inline const char *wine_dbgstr_wn( const WCHAR *str, int n )
*dst++ = hex[(c >> 4) & 0x0f];
*dst++ = hex[c & 0x0f];
}
else if (c >= 127)
{
DWORD reslen;
#if defined _NTSYSTEM_ || defined WINE_UNIX_LIB
reslen = ntdll_wcstoumbs(&c, 1, dst, 4, FALSE);
#else
RtlUnicodeToUTF8N(dst, 4, &reslen, &c, sizeof(c));
#endif
dst += reslen;
}
else *dst++ = (char)c;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment