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 '' '/home/centos/programming/c/gparted/tests/test_ext2.img'</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:
parent
8db9a83b39
commit
7159be9dff
|
@ -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, "&") == 0)
|
||||
{
|
||||
ret.push_back('&');
|
||||
i += 5;
|
||||
}
|
||||
else if (str.compare(i, 4, "<") == 0)
|
||||
{
|
||||
ret.push_back('<');
|
||||
i += 4;
|
||||
}
|
||||
else if (str.compare(i, 4, ">") == 0)
|
||||
{
|
||||
ret.push_back('>');
|
||||
i += 4;
|
||||
}
|
||||
else if (str.compare(i, 6, "'") == 0)
|
||||
{
|
||||
ret.push_back('\'');
|
||||
i += 6;
|
||||
}
|
||||
else if (str.compare(i, 6, """) == 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;
|
||||
|
|
Loading…
Reference in New Issue