mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-24 20:01:53 +00:00
If a the contents of a binary XML element only contain ASCII chars then write them in ASCII format instead of hex.
This commit is contained in:
parent
3bb0591e5c
commit
d155287638
@ -38,25 +38,44 @@ print_binary(int level,
|
|||||||
const unsigned char *p;
|
const unsigned char *p;
|
||||||
string s;
|
string s;
|
||||||
int i, size;
|
int i, size;
|
||||||
|
bool ascii_only;
|
||||||
|
|
||||||
b = (EbmlBinary *)e;
|
b = (EbmlBinary *)e;
|
||||||
p = (const unsigned char *)b->GetBuffer();
|
p = (const unsigned char *)b->GetBuffer();
|
||||||
size = b->GetSize();
|
size = b->GetSize();
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
ascii_only = true;
|
||||||
if ((i % 16) != 0)
|
for (i = 0; i < size; i++)
|
||||||
s += " ";
|
if ((p[i] < ' ') || (p[i] > 127)) {
|
||||||
s += mxsprintf("%02x", *p);
|
ascii_only = false;
|
||||||
++p;
|
break;
|
||||||
if ((((i + 1) % 16) == 0) && ((i + 1) < size))
|
}
|
||||||
s += mxsprintf("\n%*s", (level + 1) * 2, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((level * 2 + 2 * strlen(name) + 2 + 3 + s.length()) <= 78)
|
if (ascii_only) {
|
||||||
out->printf("%s</%s>\n", s.c_str(), name);
|
s.append((const char *)p, size);
|
||||||
else
|
out->printf("<%s format=\"ascii\">%s</%s>\n", name, escape_xml(s).c_str(),
|
||||||
out->printf("\n%*s%s\n%*s</%s>\n", (level + 1) * 2, "", s.c_str(),
|
name);
|
||||||
level * 2, "", name);
|
|
||||||
|
} else {
|
||||||
|
string prefix;
|
||||||
|
|
||||||
|
prefix = mxsprintf("<%s format=\"hex\">", name);
|
||||||
|
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
if ((i % 16) != 0)
|
||||||
|
s += " ";
|
||||||
|
s += mxsprintf("%02x", *p);
|
||||||
|
++p;
|
||||||
|
if ((((i + 1) % 16) == 0) && ((i + 1) < size))
|
||||||
|
s += mxsprintf("\n%*s", (level + 1) * 2, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((level * 2 + 2 * strlen(name) + 2 + 3 + s.length()) <= 78)
|
||||||
|
out->printf("%s%s</%s>\n", prefix.c_str(), s.c_str(), name);
|
||||||
|
else
|
||||||
|
out->printf("%s\n%*s%s\n%*s</%s>\n", prefix.c_str(), (level + 1) * 2, "",
|
||||||
|
s.c_str(), level * 2, "", name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -82,17 +101,15 @@ write_xml_element_rec(int level,
|
|||||||
elt_idx++;
|
elt_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < level; i++)
|
out->printf("%*s", level * 2, "");
|
||||||
out->printf(" ");
|
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
out->printf("<!-- Unknown element '%s' -->\n", e->Generic().DebugName);
|
out->printf("<!-- Unknown element '%s' -->\n", e->Generic().DebugName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
out->printf("<%s%s>", element_map[elt_idx].name,
|
if (element_map[elt_idx].type != EBMLT_BINARY)
|
||||||
element_map[elt_idx].type == EBMLT_BINARY ?
|
out->printf("<%s>", element_map[elt_idx].name);
|
||||||
" format=\"hex\"" : "");
|
|
||||||
switch (element_map[elt_idx].type) {
|
switch (element_map[elt_idx].type) {
|
||||||
case EBMLT_MASTER:
|
case EBMLT_MASTER:
|
||||||
out->printf("\n");
|
out->printf("\n");
|
||||||
@ -113,9 +130,7 @@ write_xml_element_rec(int level,
|
|||||||
element_map[elt_idx].end_hook(&cb);
|
element_map[elt_idx].end_hook(&cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < level; i++)
|
out->printf("%*s</%s>\n", level * 2, "", element_map[elt_idx].name);
|
||||||
out->printf(" ");
|
|
||||||
out->printf("</%s>\n", element_map[elt_idx].name);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EBMLT_UINT:
|
case EBMLT_UINT:
|
||||||
|
Loading…
Reference in New Issue
Block a user