[gnome-software] Move a utility function to gs-utils
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Move a utility function to gs-utils
- Date: Sat, 7 Sep 2013 16:33:10 +0000 (UTC)
commit e4bd54fa1df940d9482ffea84b3f28cbf6fdc8dd
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Sep 7 12:32:23 2013 -0400
Move a utility function to gs-utils
The gs_string_replace function is not really very specific
to the app widget, so move it to utils.
src/gs-app-widget.c | 40 ++--------------------------------------
src/gs-utils.c | 36 ++++++++++++++++++++++++++++++++++++
src/gs-utils.h | 2 ++
3 files changed, 40 insertions(+), 38 deletions(-)
---
diff --git a/src/gs-app-widget.c b/src/gs-app-widget.c
index 4008e2f..7e2f4b1 100644
--- a/src/gs-app-widget.c
+++ b/src/gs-app-widget.c
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include "gs-app-widget.h"
+#include "gs-utils.h"
#include "ch-markdown.h"
struct _GsAppWidgetPrivate
@@ -51,43 +52,6 @@ enum {
static guint signals [SIGNAL_LAST] = { 0 };
-static guint
-_g_string_replace (GString *string, const gchar *search, const gchar *replace)
-{
- gchar *tmp;
- guint cnt = 0;
- guint replace_len;
- guint search_len;
-
- search_len = strlen (search);
- replace_len = strlen (replace);
-
- do {
- tmp = g_strstr_len (string->str, -1, search);
- if (tmp == NULL)
- goto out;
-
- /* reallocate the string if required */
- if (search_len > replace_len) {
- g_string_erase (string,
- tmp - string->str,
-- search_len - replace_len);
- }
- if (search_len < replace_len) {
- g_string_insert_len (string,
- tmp - string->str,
- search,
- replace_len - search_len);
- }
-
- /* just memcmp in the new string */
- memcpy (tmp, replace, replace_len);
- cnt++;
- } while (TRUE);
-out:
- return cnt;
-}
-
/**
* gs_app_widget_refresh:
**/
@@ -114,7 +78,7 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
/* join the lines*/
str = g_string_new (tmp);
- _g_string_replace (str, "\n", " ");
+ gs_string_replace (str, "\n", " ");
gtk_label_set_label (GTK_LABEL (priv->description_label), str->str);
g_string_free (str, TRUE);
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 999dc2a..23d2e2c 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -172,3 +172,39 @@ gs_app_notify_installed (GsApp *app)
g_free (summary);
}
+guint
+gs_string_replace (GString *string, const gchar *search, const gchar *replace)
+{
+ gchar *tmp;
+ guint count = 0;
+ guint replace_len;
+ guint search_len;
+
+ search_len = strlen (search);
+ replace_len = strlen (replace);
+
+ do {
+ tmp = g_strstr_len (string->str, -1, search);
+ if (tmp == NULL)
+ goto out;
+
+ /* reallocate the string if required */
+ if (search_len > replace_len) {
+ g_string_erase (string,
+ tmp - string->str,
+- search_len - replace_len);
+ }
+ if (search_len < replace_len) {
+ g_string_insert_len (string,
+ tmp - string->str,
+ search,
+ replace_len - search_len);
+ }
+
+ /* just memcmp in the new string */
+ memcpy (tmp, replace, replace_len);
+ count++;
+ } while (TRUE);
+out:
+ return count;
+}
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 2deda32..acde428 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -35,6 +35,8 @@ void gs_grab_focus_when_mapped (GtkWidget *widget);
void gs_app_notify_installed (GsApp *app);
+guint gs_string_replace (GString *string, const gchar *search, const gchar *replace);
+
G_END_DECLS
#endif /* __GS_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]