From 7159be9dff8a41a21f5cb6760edf5bd09ee1964f Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Fri, 25 Oct 2019 13:07:36 +0100 Subject: [PATCH] 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: mkfs.ext2 -F -L '' '/home/centos/programming/c/gparted/tests/test_ext2.img' 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 --- tests/test_ext2.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/tests/test_ext2.cc b/tests/test_ext2.cc index 9a0421b7..7cf45b0c 100644 --- a/tests/test_ext2.cc +++ b/tests/test_ext2.cc @@ -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, "") == 0) + i += 3; + else if (str.compare(i, 4, "") == 0) + i += 4; + else if (str.compare(i, 3, "") == 0) + i += 3; + else if (str.compare(i, 4, "") == 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;