Strip XML markup from the printed operation details (!49)

As seen in the first commit message, operation detail text is XML
encoded.  This makes it harder to read, especially commands which often
have single quotes encoded as '.   For example:

    <b><i>mkfs.ext2 -F -L &apos;&apos; &apos;/home/centos/programming/c/gparted/tests/test_ext2.img&apos;</i></b>

Strip this encoding when printing the operation details.  Now the same
example looks like:

    mkfs.ext2 -F -L '' '/home/centos/programming/c/gparted/tests/test_ext2.img'

Closes !49 - Add file system interface tests
This commit is contained in:
Mike Fleetwood 2019-10-25 13:07:36 +01:00 committed by Curtis Gedak
parent 8db9a83b39
commit 7159be9dff
1 changed files with 55 additions and 2 deletions

View File

@ -61,6 +61,60 @@ namespace GParted
{
// Hacky XML parser which strips italic and bold markup added in
// OperationDetail::set_description() and reverts just these 5 characters &<>'" encoded by
// Glib::Markup::escape_text() -> g_markup_escape_text() -> append_escaped_text().
Glib::ustring strip_markup(const Glib::ustring& str)
{
size_t len = str.length();
size_t i = 0;
Glib::ustring ret;
ret.reserve(len);
while (i < len)
{
if (str.compare(i, 3, "<i>") == 0)
i += 3;
else if (str.compare(i, 4, "</i>") == 0)
i += 4;
else if (str.compare(i, 3, "<b>") == 0)
i += 3;
else if (str.compare(i, 4, "</b>") == 0)
i += 4;
else if (str.compare(i, 5, "&amp;") == 0)
{
ret.push_back('&');
i += 5;
}
else if (str.compare(i, 4, "&lt;") == 0)
{
ret.push_back('<');
i += 4;
}
else if (str.compare(i, 4, "&gt;") == 0)
{
ret.push_back('>');
i += 4;
}
else if (str.compare(i, 6, "&apos;") == 0)
{
ret.push_back('\'');
i += 6;
}
else if (str.compare(i, 6, "&quot;") == 0)
{
ret.push_back('"');
i += 6;
}
else
{
ret.push_back(str[i]);
i++;
}
}
return ret;
}
// Print method for OperationDetailStatus.
std::ostream& operator<<(std::ostream& out, const OperationDetailStatus od_status)
{
@ -81,8 +135,7 @@ std::ostream& operator<<(std::ostream& out, const OperationDetailStatus od_statu
// Print method for an OperationDetail object.
std::ostream& operator<<(std::ostream& out, const OperationDetail& od)
{
// FIXME: Strip markup from the printed description
out << od.get_description();
out << strip_markup(od.get_description());
Glib::ustring elapsed = od.get_elapsed_time();
if (! elapsed.empty())
out << " " << elapsed;