]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Migrated element validator to GValue.
authorAndrea Zagli <azagli@libero.it>
Sun, 20 Dec 2020 09:02:44 +0000 (10:02 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 20 Dec 2020 09:02:44 +0000 (10:02 +0100)
src/formelement.c
src/formelementvalidator.c
src/formelementvalidator.h
src/formelementvalidatordate.c
src/formelementvalidatorisnumber.c
src/formelementvalidatornotempty.c
src/formelementvalidatornumber.c
src/formelementvalidatorregex.c
src/formvalidatorcomposite.c

index 56910163a9e72222c2a694f3ad7776f9ab7708b1..c4364f211d69a9c4b3122535f50c9030b03a41ae 100644 (file)
@@ -1327,7 +1327,7 @@ zak_form_element_is_valid (ZakFormElement *element)
        gboolean ret;
        gboolean ret_callback;
 
-       gchar *value;
+       GValue *value;
        guint i;
 
        ZakFormElementPrivate *priv;
@@ -1362,7 +1362,7 @@ zak_form_element_is_valid (ZakFormElement *element)
                }
        else
                {
-                       value = zak_form_element_get_value (element);
+                       value = zak_form_element_get_value_gvalue (element);
 
                        for (i = 0; i < priv->pa_validators->len; i++)
                                {
index d3f7edd755c144292f768eb36983380b6f871866..8a51df9c1cc62715d789694fe05154025e0ba730 100644 (file)
@@ -134,7 +134,7 @@ zak_form_element_validator_xml_parsing (ZakFormElementValidator *self, xmlNode *
 }
 
 gboolean
-zak_form_element_validator_validate (ZakFormElementValidator *self, const gchar *value)
+zak_form_element_validator_validate (ZakFormElementValidator *self, GValue *value)
 {
        gboolean ret;
 
index e6c6bf3fde09a4903f553f67f20b77f0224eaf86..56e4ba922b7eeb29634f754d41119a6f26e03db9 100644 (file)
@@ -35,13 +35,13 @@ struct _ZakFormElementValidatorClass
        GObjectClass parent_class;
 
        gboolean (*xml_parsing) (ZakFormElementValidator *self, xmlNode *xnode);
-       gboolean (*validate) (ZakFormElementValidator *self, const gchar *value);
+       gboolean (*validate) (ZakFormElementValidator *self, GValue *value);
 
        void (*get_xml) (ZakFormElementValidator *self, xmlNode *xnode, const gchar *version);
 };
 
 gboolean zak_form_element_validator_xml_parsing (ZakFormElementValidator *self, xmlNode *xnode);
-gboolean zak_form_element_validator_validate (ZakFormElementValidator *self, const gchar *value);
+gboolean zak_form_element_validator_validate (ZakFormElementValidator *self, GValue *value);
 
 void zak_form_element_validator_set_id (ZakFormElementValidator *validator,
                                         const gchar *id);
index 7c2ba0572fb730d025a5a861fac1cb66e25d2c14..af02b1fd63e2fc0fe55ada475e4910e2dddc1fb4 100644 (file)
@@ -43,7 +43,7 @@ static void zak_form_element_validator_date_dispose (GObject *gobject);
 static void zak_form_element_validator_date_finalize (GObject *gobject);
 
 static gboolean zak_form_element_validator_date_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
-static gboolean zak_form_element_validator_date_validate (ZakFormElementValidator *validator_date, const gchar *value);
+static gboolean zak_form_element_validator_date_validate (ZakFormElementValidator *validator_date, GValue *value);
 static void zak_form_element_validator_date_get_xml (ZakFormElementValidator *validator, xmlNode *xnode, const gchar *version);
 
 struct _ZakFormElementValidatorDate
@@ -296,7 +296,7 @@ zak_form_element_validator_date_finalize (GObject *gobject)
 
 static gboolean
 zak_form_element_validator_date_validate (ZakFormElementValidator *validator_date,
-                                          const gchar *value)
+                                          GValue *value)
 {
        gboolean ret;
        gchar *_value;
@@ -309,11 +309,12 @@ zak_form_element_validator_date_validate (ZakFormElementValidator *validator_dat
        ZakFormElementValidatorDatePrivate *priv = zak_form_element_validator_date_get_instance_private (ZAK_FORM_ELEMENT_VALIDATOR_DATE (validator_date));
 
        g_return_val_if_fail (value != NULL, FALSE);
+       g_return_val_if_fail (G_VALUE_HOLDS_STRING (value), FALSE);
 
        gdt = NULL;
        gdt_compare = NULL;
 
-       _value = g_strstrip (g_strdup (value));
+       _value = g_strstrip (g_strdup (g_value_get_string (value)));
        if (g_strcmp0 (_value, "") == 0)
                {
                        ret = TRUE;
index 15216a928d140a93e565877e8f644f0576385c6a..9ea64fa851b3cb7726668c2206865d2b35449efd 100644 (file)
@@ -44,7 +44,7 @@ static void zak_form_element_validator_is_number_dispose (GObject *gobject);
 static void zak_form_element_validator_is_number_finalize (GObject *gobject);
 
 static gboolean zak_form_element_validator_is_number_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
-static gboolean zak_form_element_validator_is_number_validate (ZakFormElementValidator *validator_is_number, const gchar *value);
+static gboolean zak_form_element_validator_is_number_validate (ZakFormElementValidator *validator_is_number, GValue *value);
 static void zak_form_element_validator_is_number_get_xml (ZakFormElementValidator *validator, xmlNode *xnode, const gchar *version);
 
 struct _ZakFormElementValidatorIsNumber
@@ -286,7 +286,7 @@ zak_form_element_validator_is_number_finalize (GObject *gobject)
 
 static gboolean
 zak_form_element_validator_is_number_validate (ZakFormElementValidator *validator_is_number,
-                                              const gchar *value)
+                                               GValue *value)
 {
        gchar *_value;
 
@@ -300,8 +300,9 @@ zak_form_element_validator_is_number_validate (ZakFormElementValidator *validato
        ZakFormElementValidatorIsNumberPrivate *priv = zak_form_element_validator_is_number_get_instance_private (ZAK_FORM_ELEMENT_VALIDATOR_IS_NUMBER (validator_is_number));
 
        g_return_val_if_fail (value != NULL, FALSE);
+       g_return_val_if_fail (G_VALUE_HOLDS_STRING (value), FALSE);
 
-       _value = g_strstrip (g_strdup (value));
+       _value = g_strstrip (g_strdup (g_value_get_string (value)));
        validator = zak_form_element_validator_regex_new ();
 
        regex = g_string_new ("^");
@@ -339,7 +340,7 @@ zak_form_element_validator_is_number_validate (ZakFormElementValidator *validato
 
        g_string_free (regex, TRUE);
 
-       return zak_form_element_validator_validate (ZAK_FORM_ELEMENT_VALIDATOR (validator), _value);
+       return zak_form_element_validator_validate (ZAK_FORM_ELEMENT_VALIDATOR (validator), zak_utils_gvalue_new_string (_value));
 }
 
 static void
index 3c7ac71338ee779542ad55b5a32fbb0d5de0a9ec..9ec3e1c74206a4e4585f7323c621d8798d61d282 100644 (file)
@@ -45,7 +45,7 @@ static void zak_form_element_validator_notempty_dispose (GObject *gobject);
 static void zak_form_element_validator_notempty_finalize (GObject *gobject);
 
 static gboolean zak_form_element_validator_notempty_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
-static gboolean zak_form_element_validator_notempty_validate (ZakFormElementValidator *validator_notempty, const gchar *value);
+static gboolean zak_form_element_validator_notempty_validate (ZakFormElementValidator *validator_notempty, GValue *value);
 static void zak_form_element_validator_notempty_get_xml (ZakFormElementValidator *validator, xmlNode *xnode, const gchar *version);
 
 struct _ZakFormElementValidatorNotempty
@@ -242,7 +242,7 @@ zak_form_element_validator_notempty_finalize (GObject *gobject)
 
 static gboolean
 zak_form_element_validator_notempty_validate (ZakFormElementValidator *validator,
-                                              const gchar *value)
+                                              GValue *value)
 {
        gboolean ret;
 
@@ -250,7 +250,7 @@ zak_form_element_validator_notempty_validate (ZakFormElementValidator *validator
 
        g_return_val_if_fail (value != NULL, FALSE);
 
-       ret = (g_strcmp0 (value, priv->as_empty_string) != 0);
+       ret = (g_strcmp0 (g_value_get_string (value), priv->as_empty_string) != 0);
 
        return ret;
 }
index 6304386da704cd76408bf5794115dcd416697599..9cab457055f925bb812f2a07d7c6c94aadb2c51d 100644 (file)
@@ -43,7 +43,7 @@ static void zak_form_element_validator_number_dispose (GObject *gobject);
 static void zak_form_element_validator_number_finalize (GObject *gobject);
 
 static gboolean zak_form_element_validator_number_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
-static gboolean zak_form_element_validator_number_validate (ZakFormElementValidator *validator_number, const gchar *value);
+static gboolean zak_form_element_validator_number_validate (ZakFormElementValidator *validator_number, GValue *value);
 static void zak_form_element_validator_number_get_xml (ZakFormElementValidator *validator, xmlNode *xnode, const gchar *version);
 
 struct _ZakFormElementValidatorNumber
@@ -250,7 +250,7 @@ zak_form_element_validator_number_finalize (GObject *gobject)
 
 static gboolean
 zak_form_element_validator_number_validate (ZakFormElementValidator *validator_number,
-                                          const gchar *value)
+                                            GValue *value)
 {
        gboolean ret;
 
@@ -262,7 +262,7 @@ zak_form_element_validator_number_validate (ZakFormElementValidator *validator_n
 
        g_return_val_if_fail (value != NULL, FALSE);
 
-       _value = g_strtod (value, NULL);
+       _value = g_strtod (g_value_get_string (value), NULL);
 
        if (_value < priv->compare_value)
                {
index 96f1e3f03bb301d20cc6e9cd285997a86bfac6e6..973187f02fb3d29fe5bf803abf55d6aaa52545ae 100644 (file)
@@ -45,7 +45,7 @@ static void zak_form_element_validator_regex_dispose (GObject *gobject);
 static void zak_form_element_validator_regex_finalize (GObject *gobject);
 
 static gboolean zak_form_element_validator_regex_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
-static gboolean zak_form_element_validator_regex_validate (ZakFormElementValidator *validator_regex, const gchar *value);
+static gboolean zak_form_element_validator_regex_validate (ZakFormElementValidator *validator_regex, GValue *value);
 static void zak_form_element_validator_regex_get_xml (ZakFormElementValidator *validator, xmlNode *xnode, const gchar *version);
 
 struct _ZakFormElementValidatorRegex
@@ -232,7 +232,7 @@ zak_form_element_validator_regex_finalize (GObject *gobject)
 
 static gboolean
 zak_form_element_validator_regex_validate (ZakFormElementValidator *validator_regex,
-                                           const gchar *value)
+                                           GValue *value)
 {
        gboolean ret;
 
@@ -240,6 +240,7 @@ zak_form_element_validator_regex_validate (ZakFormElementValidator *validator_re
        GError *error;
 
        g_return_val_if_fail (value != NULL, FALSE);
+       g_return_val_if_fail (G_VALUE_HOLDS_STRING (value), FALSE);
 
        ZakFormElementValidatorRegexPrivate *priv = zak_form_element_validator_regex_get_instance_private (ZAK_FORM_ELEMENT_VALIDATOR_REGEX (validator_regex));
 
@@ -254,14 +255,14 @@ zak_form_element_validator_regex_validate (ZakFormElementValidator *validator_re
                || error != NULL)
                {
                        g_warning ("Error on creating regex: %s.",
-                                          error->message != NULL ? error->message : "no details");
+                                  error->message != NULL ? error->message : "no details");
                        return FALSE;
                }
 
-       ret = g_regex_match ((const GRegex *)regex, value, 0, NULL);
+       ret = g_regex_match ((const GRegex *)regex, g_value_get_string (value), 0, NULL);
        if (!ret)
                {
-                       g_warning ("Value «%s» not valid for regex «%s».", value, priv->regex);
+                       g_warning ("Value «%s» not valid for regex «%s».", g_value_get_string (value), priv->regex);
                }
 
        return ret;
index 5817c6893fe24353f960ab78ab8b06627cd08ebd..e4a13d81234878b85aa9510cc1182c69320a4c88 100644 (file)
@@ -442,7 +442,7 @@ _zak_form_validator_composite_validate (ZakFormValidator *validator, GNode *pare
                                        else
                                                {
                                                        if (zak_form_element_validator_validate (n_child->element_validator,
-                                                                                                zak_form_element_get_value (n_child->element)) == n_child->condition_type)
+                                                                                                zak_form_element_get_value_gvalue (n_child->element)) == n_child->condition_type)
                                                                {
                                                                        switch (n->logic_type)
                                                                                {
@@ -475,7 +475,7 @@ _zak_form_validator_composite_validate (ZakFormValidator *validator, GNode *pare
                                                                        else
                                                                                {
                                                                                        ret = (ret && zak_form_element_validator_validate (n_child->element_validator,
-                                                                                                                                          zak_form_element_get_value (n_child->element)));
+                                                                                                                                          zak_form_element_get_value_gvalue (n_child->element)));
                                                                                }
                                                                }
                                                        break;
@@ -494,7 +494,7 @@ _zak_form_validator_composite_validate (ZakFormValidator *validator, GNode *pare
                                                                        else
                                                                                {
                                                                                        ret = (ret || zak_form_element_validator_validate (n_child->element_validator,
-                                                                                                                                          zak_form_element_get_value (n_child->element)));
+                                                                                                                                          zak_form_element_get_value_gvalue (n_child->element)));
                                                                                }
                                                                }
                                                        break;