Title: [128908] trunk/Source/WTF
Revision
128908
Author
[email protected]
Date
2012-09-18 10:57:33 -0700 (Tue, 18 Sep 2012)

Log Message

WTFString::show doesn't dump non-ASCII characters in a readable manner
https://bugs.webkit.org/show_bug.cgi?id=96749

Patch by Glenn Adams <[email protected]> on 2012-09-18
Reviewed by Benjamin Poulain.

Dump non-ASCII characters in a useful form for debugging.

* wtf/text/WTFString.cpp:
(asciiDebug):
Dump non-ASCII characters (i.e., UTF-16 code elements) as well as non-printable ASCII characters
using \uXXXX format. Also escape \ as \\ in order to remove ambiguity.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (128907 => 128908)


--- trunk/Source/WTF/ChangeLog	2012-09-18 17:54:14 UTC (rev 128907)
+++ trunk/Source/WTF/ChangeLog	2012-09-18 17:57:33 UTC (rev 128908)
@@ -1,3 +1,17 @@
+2012-09-18  Glenn Adams  <[email protected]>
+
+        WTFString::show doesn't dump non-ASCII characters in a readable manner
+        https://bugs.webkit.org/show_bug.cgi?id=96749
+
+        Reviewed by Benjamin Poulain.
+
+        Dump non-ASCII characters in a useful form for debugging.
+
+        * wtf/text/WTFString.cpp:
+        (asciiDebug):
+        Dump non-ASCII characters (i.e., UTF-16 code elements) as well as non-printable ASCII characters
+        using \uXXXX format. Also escape \ as \\ in order to remove ambiguity.
+
 2012-09-18  Mark Hahnenberg  <[email protected]>
 
         Use WTF::HasTrivialDestructor instead of compiler-specific versions in JSC::NeedsDestructor

Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (128907 => 128908)


--- trunk/Source/WTF/wtf/text/WTFString.cpp	2012-09-18 17:54:14 UTC (rev 128907)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp	2012-09-18 17:57:33 UTC (rev 128908)
@@ -26,6 +26,7 @@
 #include <stdarg.h>
 #include <wtf/ASCIICType.h>
 #include <wtf/DataLog.h>
+#include <wtf/HexNumber.h>
 #include <wtf/MathExtras.h>
 #include <wtf/MemoryInstrumentation.h>
 #include <wtf/text/CString.h>
@@ -1135,16 +1136,19 @@
         return asciiDebug(String("[null]").impl());
 
     Vector<char> buffer;
-    unsigned length = impl->length();
-    const UChar* characters = impl->characters();
-
-    buffer.resize(length + 1);
-    for (unsigned i = 0; i < length; ++i) {
-        UChar ch = characters[i];
-        buffer[i] = ch && (ch < 0x20 || ch > 0x7f) ? '?' : ch;
+    for (unsigned i = 0; i < impl->length(); ++i) {
+        UChar ch = (*impl)[i];
+        if (isASCIIPrintable(ch)) {
+            if (ch == '\\')
+                buffer.append(ch);
+            buffer.append(ch);
+        } else {
+            buffer.append('\\');
+            buffer.append('u');
+            appendUnsignedAsHexFixedSize(ch, buffer, 4);
+        }
     }
-    buffer[length] = '\0';
-
+    buffer.append('\0');
     return buffer;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to