[gnome-control-center] info: remove duplicate whitespace from cpu model
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] info: remove duplicate whitespace from cpu model
- Date: Tue, 18 Jan 2011 22:06:47 +0000 (UTC)
commit faace48daa651ad0ac7f4ae634c73f78030e4d92
Author: William Jon McCann <jmccann redhat com>
Date: Tue Jan 18 17:00:11 2011 -0500
info: remove duplicate whitespace from cpu model
panels/info/cc-info-panel.c | 45 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/panels/info/cc-info-panel.c b/panels/info/cc-info-panel.c
index c051d11..51f8c49 100644
--- a/panels/info/cc-info-panel.c
+++ b/panels/info/cc-info-panel.c
@@ -263,6 +263,40 @@ get_primary_disc_info (void)
}
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;
@@ -303,11 +337,16 @@ get_cpu_info (const glibtop_sysinfo *info)
g_hash_table_iter_init (&iter, counts);
while (g_hash_table_iter_next (&iter, &key, &value))
{
- int count = GPOINTER_TO_INT (value);
+ char *stripped;
+ int count;
+
+ count = GPOINTER_TO_INT (value);
+ stripped = remove_duplicate_whitespace ((const char *)key);
if (count > 1)
- g_string_append_printf (cpu, "%s \303\227 %d ", (char *)key, count);
+ g_string_append_printf (cpu, "%s \303\227 %d ", stripped, count);
else
- g_string_append_printf (cpu, "%s ", (char *)key);
+ g_string_append_printf (cpu, "%s ", stripped);
+ g_free (stripped);
}
g_hash_table_destroy (counts);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]