forked from osmocom/wireshark
wslog: Improve display for UTF-8 strings
Print the valid substring as UTF-8, not ASCII+hex.
This commit is contained in:
parent
0662a3f6ac
commit
46d018627b
|
@ -1128,28 +1128,25 @@ static char *
|
||||||
make_utf8_display(const char *src, size_t src_length, size_t good_length)
|
make_utf8_display(const char *src, size_t src_length, size_t good_length)
|
||||||
{
|
{
|
||||||
wmem_strbuf_t *buf;
|
wmem_strbuf_t *buf;
|
||||||
char ch;
|
unsigned char ch;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
|
||||||
buf = wmem_strbuf_new(NULL, NULL);
|
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];
|
ch = src[pos];
|
||||||
if (pos < good_length) {
|
wmem_strbuf_append_c(buf, ch);
|
||||||
if (g_ascii_isalnum(ch) || ch == ' ') {
|
if ((ch >> 6) != 2) {
|
||||||
wmem_strbuf_append_c(buf, ch);
|
/* first byte */
|
||||||
offset += 1;
|
offset += 1;
|
||||||
}
|
|
||||||
else {
|
|
||||||
wmem_strbuf_append_hex(buf, ch);
|
|
||||||
offset += 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
wmem_strbuf_append_hex(buf, ch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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');
|
wmem_strbuf_append_c(buf, '\n');
|
||||||
|
|
||||||
for (size_t pos = 0; pos < offset; pos++) {
|
for (size_t pos = 0; pos < offset; pos++) {
|
||||||
wmem_strbuf_append_c(buf, ' ');
|
wmem_strbuf_append_c(buf, ' ');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue