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
This commit is contained in:
Bastien Nocera 2016-11-16 16:10:52 +01:00
parent 34b1d0d083
commit 52da4dafeb
3 changed files with 47 additions and 42 deletions

View file

@ -618,40 +618,6 @@ get_primary_disc_info (CcInfoPanel *self)
get_primary_disc_info_start (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)
{
@ -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;
}

View file

@ -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

View file

@ -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;
}