Commit faace48d authored by William Jon McCann's avatar William Jon McCann

info: remove duplicate whitespace from cpu model

parent c688a246
......@@ -262,6 +262,40 @@ get_primary_disc_info (void)
return g_format_size_for_display (total_bytes);
}
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)
{
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment