From 845fc34bc89845e749c30ad2a193bb583175ae86 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 13 May 2017 11:28:12 +0200 Subject: [PATCH] Migration to GValue for element value. --- src/form.c | 2 +- src/formelement.c | 22 ++++++++++++---------- src/formelement.h | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/form.c b/src/form.c index d2005d6..9cf7abc 100644 --- a/src/form.c +++ b/src/form.c @@ -152,7 +152,7 @@ zak_form_cgi_form_bind (ZakFormCgiForm *zakcgiform) gval = zak_cgi_main_get_stdin_field (priv->zakcgimain, zak_form_cgi_form_element_get_id (element)); if (gval != NULL) { - zak_form_cgi_form_element_bind (element, g_value_get_string (gval)); + zak_form_cgi_form_element_bind (element, gval); } } } diff --git a/src/formelement.c b/src/formelement.c index b3a790a..ce14157 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -20,7 +20,9 @@ #include #endif +#include #include + #include "formelement.h" enum @@ -50,8 +52,8 @@ static void zak_form_cgi_form_element_get_property (GObject *object, static void zak_form_cgi_form_element_dispose (GObject *gobject); static void zak_form_cgi_form_element_finalize (GObject *gobject); -static gchar *zak_form_cgi_form_element_get_value (ZakFormCgiFormElement *element); -static gboolean zak_form_cgi_form_element_set_value (ZakFormCgiFormElement *element, const gchar *value); +static GValue *zak_form_cgi_form_element_get_value (ZakFormCgiFormElement *element); +static gboolean zak_form_cgi_form_element_set_value (ZakFormCgiFormElement *element, GValue *value); static void zak_form_cgi_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode); #define ZAK_FORM_CGI_FORM_ELEMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_CGI_TYPE_FORM_ELEMENT, ZakFormCgiFormElementPrivate)) @@ -62,7 +64,7 @@ struct _ZakFormCgiFormElementPrivate gchar *id; GHashTable *ht_attrs; GHashTable *ht_label_attrs; - gchar *value; + GValue *value; }; G_DEFINE_TYPE (ZakFormCgiFormElement, zak_form_cgi_form_element, ZAK_FORM_TYPE_ELEMENT) @@ -154,13 +156,13 @@ zak_form_cgi_form_element_set_label (ZakFormCgiFormElement *element, const gchar * */ void -zak_form_cgi_form_element_bind (ZakFormCgiFormElement *element, const gchar *value) +zak_form_cgi_form_element_bind (ZakFormCgiFormElement *element, GValue *value) { ZakFormCgiFormElementPrivate *priv; priv = ZAK_FORM_CGI_FORM_ELEMENT_GET_PRIVATE (element); - priv->value = g_strdup (value); + priv->value = value; } /** @@ -330,28 +332,28 @@ static GHashTable return priv->ht_label_attrs; } -static gchar +static GValue *zak_form_cgi_form_element_get_value (ZakFormCgiFormElement *element) { - gchar *ret; + GValue *ret; ZakFormCgiFormElementPrivate *priv; priv = ZAK_FORM_CGI_FORM_ELEMENT_GET_PRIVATE (element); - ret = g_strdup (priv->value); + ret = priv->value; return ret; } static gboolean -zak_form_cgi_form_element_set_value (ZakFormCgiFormElement *element, const gchar *value) +zak_form_cgi_form_element_set_value (ZakFormCgiFormElement *element, GValue *value) { ZakFormCgiFormElementPrivate *priv; priv = ZAK_FORM_CGI_FORM_ELEMENT_GET_PRIVATE (element); - priv->value = g_strdup (value); + priv->value = value; return TRUE; } diff --git a/src/formelement.h b/src/formelement.h index 23c3de8..7908571 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -50,7 +50,7 @@ gchar *zak_form_cgi_form_element_get_id (ZakFormCgiFormElement *element); void zak_form_cgi_form_element_set_label (ZakFormCgiFormElement *element, const gchar *label, ...); -void zak_form_cgi_form_element_bind (ZakFormCgiFormElement *element, const gchar *value); +void zak_form_cgi_form_element_bind (ZakFormCgiFormElement *element, GValue *value); gchar *zak_form_cgi_form_element_render (ZakFormCgiFormElement *element); gchar *zak_form_cgi_form_element_render_label (ZakFormCgiFormElement *element); -- 2.49.0