]> git.cworth.org Git - apitrace/commitdiff
Dump wchar_t strings correctly.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 25 Jun 2009 12:56:18 +0000 (13:56 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 25 Jun 2009 12:56:18 +0000 (13:56 +0100)
base.py
log.cpp
log.hpp
windows.py

diff --git a/base.py b/base.py
index 0dbec4c3ea34cc880e9ec8b30806353efec24f85..c27a3c23760d12abd3a018ea728f618cd1dd9970 100644 (file)
--- 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 1c1804f61155c52aba5f45b7f23682213be2afa2..ac1787b19184eb016112897c5a5178c4aa1895e2 100644 (file)
--- 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 87ca4e941ab1764c6335b78ca454e3dbf5c0f19d..c44920f98f242b2c3f4d968b4600ebdf63ad05ec 100644 (file)
--- 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);
     
 }
 
index 59d659180d1c419eb48a45ad164cdeb0881b9bc1..032b87b1f4967093dd6e79e88d8cfb1cca69f141 100644 (file)
@@ -46,7 +46,8 @@ LPSIZE = LPDWORD
 
 LPSTR = String
 LPCSTR = Const(String)
-LPWSTR = String
+LPWSTR = WString
+LPCWSTR = WString
 
 LARGE_INTEGER = Intrinsic("LARGE_INTEGER", "0x%llx")