wslog: Improve display for UTF-8 strings

Print the valid substring as UTF-8, not ASCII+hex.
This commit is contained in:
João Valverde 2022-10-08 10:41:35 +01:00 committed by A Wireshark GitLab Utility
parent 0662a3f6ac
commit 46d018627b
1 changed files with 11 additions and 14 deletions

View File

@ -1128,28 +1128,25 @@ static char *
make_utf8_display(const char *src, size_t src_length, size_t good_length)
{
wmem_strbuf_t *buf;
char ch;
unsigned char ch;
size_t offset = 0;
buf = wmem_strbuf_new(NULL, NULL);
for (size_t pos = 0; pos < src_length; pos++) {
for (size_t pos = 0; pos < good_length; pos++) {
ch = src[pos];
if (pos < good_length) {
if (g_ascii_isalnum(ch) || ch == ' ') {
wmem_strbuf_append_c(buf, ch);
offset += 1;
}
else {
wmem_strbuf_append_hex(buf, ch);
offset += 4;
}
}
else {
wmem_strbuf_append_hex(buf, ch);
wmem_strbuf_append_c(buf, ch);
if ((ch >> 6) != 2) {
/* first byte */
offset += 1;
}
}
for (size_t pos = good_length; pos < src_length; pos++) {
ch = src[pos];
wmem_strbuf_append_hex(buf, ch);
}
wmem_strbuf_append_c(buf, '\n');
for (size_t pos = 0; pos < offset; pos++) {
wmem_strbuf_append_c(buf, ' ');
}