make StreamBuffer::dump nicer

This commit is contained in:
2018-07-24 15:46:11 +02:00
parent 8e02c65b09
commit 4fc619f9a4

View File

@ -287,7 +287,7 @@ StreamBuffer StreamBuffer::expand(ssize_t start, ssize_t length) const
} }
end = start+length; end = start+length;
if (end > len) end = len; if (end > len) end = len;
StreamBuffer result((end-start)*2); StreamBuffer result;
start += offs; start += offs;
end += offs; end += offs;
size_t i; size_t i;
@ -296,41 +296,30 @@ StreamBuffer StreamBuffer::expand(ssize_t start, ssize_t length) const
{ {
c = buffer[i]; c = buffer[i];
if (c < 0x20 || c >= 0x7f) if (c < 0x20 || c >= 0x7f)
{ result.print("\033[1m<%02x>\033[22m", c & 0xff);
result.print("\033[1m<%02x>\033[0m", c & 0xff);
}
else else
{
result.append(c); result.append(c);
} }
}
return result; return result;
} }
StreamBuffer StreamBuffer:: StreamBuffer StreamBuffer::
dump() const dump() const
{ {
StreamBuffer result(256+cap*5); StreamBuffer result;
result.append("\033[0m");
size_t i; size_t i;
result.print("%" P "d,%" P "d,%" P "d:\033[37m", offs, len, cap); result.print("%" P "d,%" P "d,%" P "d:", offs, len, cap);
if (offs) result.print("\033[47m");
char c;
for (i = 0; i < cap; i++) for (i = 0; i < cap; i++)
{ {
if (i == offs) result.append("\033[34m[\033[0m"); c = buffer[i];
if (buffer[i] < 0x20 || buffer[i] >= 0x7f) if (offs && i == offs) result.append("\033[0m");
{ if (c < 0x20 || c >= 0x7f)
if (i < offs || i >= offs+len) result.print("\033[1m<%02x>\033[22m", c & 0xff);
result.print(
"<%02x>", buffer[i] & 0xff);
else else
result.print( result.append(c);
"\033[34m<%02x>\033[37m", buffer[i] & 0xff); if (i == offs+len-1) result.append("\033[47m");
}
else
{
result.append(buffer[i]);
}
if (i == offs+len-1) result.append("\033[34m]\033[37m");
} }
result.append("\033[0m"); result.append("\033[0m");
return result; return result;