From e54e411c2333581b8b80021c737f0feb1ffdf7b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 25 Jun 2009 13:56:18 +0100 Subject: [PATCH] Dump wchar_t strings correctly. --- base.py | 15 ++++++++++++++- log.cpp | 32 ++++++++++++++++++++++++++++++++ log.hpp | 1 + windows.py | 3 ++- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/base.py b/base.py index 0dbec4c..c27a3c2 100644 --- a/base.py +++ b/base.py @@ -452,13 +452,26 @@ class _String(Type): Type.__init__(self, "String") def __str__(self): - return "char *" + return "const char *" def dump(self, instance): print ' Log::DumpString((const char *)%s);' % instance String = _String() +class _WString(Type): + + def __init__(self): + Type.__init__(self, "WString") + + def __str__(self): + return "const wchar_t *" + + def dump(self, instance): + print ' Log::DumpWString(%s);' % instance + +WString = _WString() + SChar = Intrinsic("signed char", "%i") UChar = Intrinsic("unsigned char", "%u") diff --git a/log.cpp b/log.cpp index 1c1804f..ac1787b 100644 --- a/log.cpp +++ b/log.cpp @@ -317,4 +317,36 @@ void DumpString(const char *str) { Log::Text("\""); } +void DumpWString(const wchar_t *str) { + const wchar_t *p = str; + Log::Text("L\""); + wchar_t c; + while((c = *p++) != 0) { + if(c == '\"') + Text("\\\""); + else if(c == '\\') + Text("\\\\"); + else if(c >= 0x20 && c <= 0x7e) + TextChar((char)c); + else if(c == '\t') + Text("\\t"); + else if(c == '\r') + Text("\\r"); + else if(c == '\n') + Text("\\n"); + else { + unsigned octal0 = c & 0x7; + unsigned octal1 = (c >> 3) & 0x7; + unsigned octal2 = (c >> 3) & 0x7; + if(octal2) + TextF("\\%u%u%u", octal2, octal1, octal0); + else if(octal1) + TextF("\\%u%u", octal1, octal0); + else + TextF("\\%u", octal0); + } + } + Log::Text("\""); +} + } /* namespace Log */ diff --git a/log.hpp b/log.hpp index 87ca4e9..c44920f 100644 --- a/log.hpp +++ b/log.hpp @@ -46,6 +46,7 @@ namespace Log { void EndReference(void); void DumpString(const char *str); + void DumpWString(const wchar_t *str); } diff --git a/windows.py b/windows.py index 59d6591..032b87b 100644 --- a/windows.py +++ b/windows.py @@ -46,7 +46,8 @@ LPSIZE = LPDWORD LPSTR = String LPCSTR = Const(String) -LPWSTR = String +LPWSTR = WString +LPCWSTR = WString LARGE_INTEGER = Intrinsic("LARGE_INTEGER", "0x%llx") -- 2.45.2