Limit the QString pretty outputs to 256 characters
Change-Id: I88e71e517827af7d82e3a47d88d40787051ed827 Reviewed-by: Sergio Ahumada <sahumada@blackberry.com>
This commit is contained in:
parent
918f20ee47
commit
df70d5ad80
@ -2143,18 +2143,26 @@ char *toHexRepresentation(const char *ba, int length)
|
|||||||
char *toPrettyUnicode(const ushort *p, int length)
|
char *toPrettyUnicode(const ushort *p, int length)
|
||||||
{
|
{
|
||||||
// keep it simple for the vast majority of cases
|
// keep it simple for the vast majority of cases
|
||||||
QScopedArrayPointer<char> buffer(new char[length * 6 + 3]);
|
bool trimmed = false;
|
||||||
|
QScopedArrayPointer<char> buffer(new char[256]);
|
||||||
const ushort *end = p + length;
|
const ushort *end = p + length;
|
||||||
char *dst = buffer.data();
|
char *dst = buffer.data();
|
||||||
|
|
||||||
*dst++ = '"';
|
*dst++ = '"';
|
||||||
for ( ; p != end; ++p) {
|
for ( ; p != end; ++p) {
|
||||||
|
if (dst - buffer.data() > 245) {
|
||||||
|
// plus the the quote, the three dots and NUL, it's 250, 251 or 255
|
||||||
|
trimmed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (*p < 0x7f && *p >= 0x20 && *p != '\\') {
|
if (*p < 0x7f && *p >= 0x20 && *p != '\\') {
|
||||||
*dst++ = *p;
|
*dst++ = *p;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write as an escape sequence
|
// write as an escape sequence
|
||||||
|
// this means we may advance dst to buffer.data() + 246 or 250
|
||||||
*dst++ = '\\';
|
*dst++ = '\\';
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case 0x22:
|
case 0x22:
|
||||||
@ -2186,6 +2194,11 @@ char *toPrettyUnicode(const ushort *p, int length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*dst++ = '"';
|
*dst++ = '"';
|
||||||
|
if (trimmed) {
|
||||||
|
*dst++ = '.';
|
||||||
|
*dst++ = '.';
|
||||||
|
*dst++ = '.';
|
||||||
|
}
|
||||||
*dst++ = '\0';
|
*dst++ = '\0';
|
||||||
return buffer.take();
|
return buffer.take();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user