[gparted] Strip XML markup from the printed operation details (!49)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Strip XML markup from the printed operation details (!49)
- Date: Sat, 9 Nov 2019 17:42:11 +0000 (UTC)
commit 7159be9dff8a41a21f5cb6760edf5bd09ee1964f
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Fri Oct 25 13:07:36 2019 +0100
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
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, "<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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]