summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2017-03-08 15:10:15 +0100
committerraveit65 <[email protected]>2017-03-08 16:08:00 +0100
commit598aa8457c46dcb47e536ff9ceab0a65c07b05f9 (patch)
treed993482ae1f2e1e7ccb80c4f5b2c6e5a01745463
parentd38f3a50bcf258111c61ea1df373fc7b6763d16c (diff)
downloadmate-control-center-598aa8457c46dcb47e536ff9ceab0a65c07b05f9.tar.bz2
mate-control-center-598aa8457c46dcb47e536ff9ceab0a65c07b05f9.tar.xz
font-viewer font-view: fix a runtime warning
font-view: strip empty lines when they're the last line https://git.gnome.org/browse/gnome-font-viewer/commit/?h=gnome-3-6&id=f51507c font-view: strip "Version" string from the version field No need to show "Version" twice https://git.gnome.org/browse/gnome-font-viewer/commit/?h=gnome-3-6&id=2e481de
-rw-r--r--font-viewer/font-view.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/font-viewer/font-view.c b/font-viewer/font-view.c
index 0668d6cd..abf9a194 100644
--- a/font-viewer/font-view.c
+++ b/font-viewer/font-view.c
@@ -98,7 +98,7 @@ static const gchar *app_menu =
#define WHITESPACE_CHARS "\f \t"
static void
-strip_whitespace (gchar **copyright)
+strip_whitespace (gchar **original)
{
GString *reassembled;
gchar **split;
@@ -106,7 +106,7 @@ strip_whitespace (gchar **copyright)
gint idx, n_stripped;
size_t len;
- split = g_strsplit (*copyright, "\n", -1);
+ split = g_strsplit (*original, "\n", -1);
reassembled = g_string_new (NULL);
n_stripped = 0;
@@ -117,15 +117,39 @@ strip_whitespace (gchar **copyright)
if (len)
str += len;
+ if (strlen (str) == 0 &&
+ ((split[idx + 1] == NULL) || strlen (split[idx + 1]) == 0))
+ continue;
+
if (n_stripped++ > 0)
g_string_append (reassembled, "\n");
g_string_append (reassembled, str);
}
g_strfreev (split);
- g_free (*copyright);
+ g_free (*original);
+
+ *original = g_string_free (reassembled, FALSE);
+}
+
+#define MATCH_VERSION_STR "Version"
+
+static void
+strip_version (gchar **original)
+{
+ gchar *ptr, *stripped;
+
+ ptr = g_strstr_len (*original, -1, MATCH_VERSION_STR);
+ if (!ptr)
+ return;
+
+ ptr += strlen (MATCH_VERSION_STR);
+ stripped = g_strdup (ptr);
+
+ strip_whitespace (&stripped);
- *copyright = g_string_free (reassembled, FALSE);
+ g_free (*original);
+ *original = stripped;
}
static void
@@ -236,15 +260,17 @@ populate_grid (FontViewApplication *self,
}
if (version) {
- add_row (grid, _("Version"), version, FALSE);
+ strip_version (&version);
+ add_row (grid, _("Version"), version, FALSE);
g_free (version);
}
if (copyright) {
strip_whitespace (&copyright);
- add_row (self->side_grid, _("Copyright"), copyright, TRUE);
+ add_row (grid, _("Copyright"), copyright, TRUE);
g_free (copyright);
}
if (description) {
+ strip_whitespace (&description);
add_row (grid, _("Description"), description, TRUE);
g_free (description);
}