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 <glenn@skynav.com> on 2012-09-14
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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@128682 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 14e823cb
2012-09-14 Glenn Adams <glenn@skynav.com>
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.
2012-09-14 Alexey Proskuryakov <ap@apple.com>
Minimize collisions when hashing pairs
......
......@@ -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,17 @@ Vector<char> asciiDebug(StringImpl* impl)
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))
buffer.append(ch);
else {
buffer.append('\\');
buffer.append('u');
appendUnsignedAsHexFixedSize(ch, buffer, 4);
}
}
buffer[length] = '\0';
buffer.append('\0');
return buffer;
}
......
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