[gnome-control-center/gnome-3-22] info: Move duplicate space removal to info-cleanup.c



commit b540bd74c00eae3e1d921d072646618a25e7ef3d
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Nov 16 16:10:52 2016 +0100

    info: Move duplicate space removal to info-cleanup.c
    
    So that we don't have to do that separately for CPUs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774240

 panels/info/cc-info-panel.c       |   47 ++++--------------------------------
 panels/info/info-cleanup-test.txt |    1 +
 panels/info/info-cleanup.c        |   41 +++++++++++++++++++++++++++++++-
 3 files changed, 47 insertions(+), 42 deletions(-)
---
diff --git a/panels/info/cc-info-panel.c b/panels/info/cc-info-panel.c
index c2eb48a..8ac1668 100644
--- a/panels/info/cc-info-panel.c
+++ b/panels/info/cc-info-panel.c
@@ -619,40 +619,6 @@ get_primary_disc_info (CcInfoPanel *self)
 }
 
 static char *
-remove_duplicate_whitespace (const char *old)
-{
-  char   *new;
-  GRegex *re;
-  GError *error;
-
-  error = NULL;
-  re = g_regex_new ("[ \t\n\r]+", G_REGEX_MULTILINE, 0, &error);
-  if (re == NULL)
-    {
-      g_warning ("Error building regex: %s", error->message);
-      g_error_free (error);
-      return g_strdup (old);
-    }
-  new = g_regex_replace (re,
-                         old,
-                         -1,
-                         0,
-                         " ",
-                         0,
-                         &error);
-  g_regex_unref (re);
-  if (new == NULL)
-    {
-      g_warning ("Error replacing string: %s", error->message);
-      g_error_free (error);
-      return g_strdup (old);
-    }
-
-  return new;
-}
-
-
-static char *
 get_cpu_info (const glibtop_sysinfo *info)
 {
   GHashTable    *counts;
@@ -694,22 +660,21 @@ get_cpu_info (const glibtop_sysinfo *info)
   g_hash_table_iter_init (&iter, counts);
   while (g_hash_table_iter_next (&iter, &key, &value))
     {
-      char *stripped;
+      char *cleanedup;
       int   count;
 
       count = GPOINTER_TO_INT (value);
-      stripped = remove_duplicate_whitespace ((const char *)key);
+      cleanedup = info_cleanup ((const char *) key);
       if (count > 1)
-        g_string_append_printf (cpu, "%s \303\227 %d ", stripped, count);
+        g_string_append_printf (cpu, "%s \303\227 %d ", cleanedup, count);
       else
-        g_string_append_printf (cpu, "%s ", stripped);
-      g_free (stripped);
+        g_string_append_printf (cpu, "%s ", cleanedup);
+      g_free (cleanedup);
     }
 
   g_hash_table_destroy (counts);
 
-  ret = info_cleanup (cpu->str);
-  g_string_free (cpu, TRUE);
+  ret = g_string_free (cpu, FALSE);
 
   return ret;
 }
diff --git a/panels/info/info-cleanup-test.txt b/panels/info/info-cleanup-test.txt
index ea4291e..eb631a5 100644
--- a/panels/info/info-cleanup-test.txt
+++ b/panels/info/info-cleanup-test.txt
@@ -1,2 +1,3 @@
 Intel(R) Core(TM) i5-4590T CPU @ 2.00GHz       Intel<sup>®</sup> Core<sup>™</sup> i5-4590T CPU @ 2.00GHz
 Intel(R) Ivybridge Mobile      Intel<sup>®</sup> Ivybridge Mobile
+Intel(R)  Ivybridge Mobile     Intel<sup>®</sup> Ivybridge Mobile
diff --git a/panels/info/info-cleanup.c b/panels/info/info-cleanup.c
index 05c162e..5bd49e8 100644
--- a/panels/info/info-cleanup.c
+++ b/panels/info/info-cleanup.c
@@ -88,8 +88,47 @@ prettify_info (const char *info)
   return pretty;
 }
 
+static char *
+remove_duplicate_whitespace (const char *old)
+{
+  char   *new;
+  GRegex *re;
+  GError *error;
+
+  error = NULL;
+  re = g_regex_new ("[ \t\n\r]+", G_REGEX_MULTILINE, 0, &error);
+  if (re == NULL)
+    {
+      g_warning ("Error building regex: %s", error->message);
+      g_error_free (error);
+      return g_strdup (old);
+    }
+  new = g_regex_replace (re,
+                         old,
+                         -1,
+                         0,
+                         " ",
+                         0,
+                         &error);
+  g_regex_unref (re);
+  if (new == NULL)
+    {
+      g_warning ("Error replacing string: %s", error->message);
+      g_error_free (error);
+      return g_strdup (old);
+    }
+
+  return new;
+}
+
 char *
 info_cleanup (const char *input)
 {
-  return prettify_info (input);
+  char *pretty, *ret;
+
+  pretty = prettify_info (input);
+  ret = remove_duplicate_whitespace (pretty);
+  g_free (pretty);
+
+  return ret;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]