]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added get/set_regex to ZakFormValidatorRegex.
authorAndrea Zagli <azagli@libero.it>
Sat, 30 Jan 2016 08:54:38 +0000 (09:54 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 30 Jan 2016 08:54:38 +0000 (09:54 +0100)
src/formelementvalidatorregex.c
src/formelementvalidatorregex.h

index 1cf81bef8b9947e0d64fd964d132c7060aa8dd1d..cd9220329d53f8a692cece136e3616e205a1022e 100644 (file)
 #include "formelementvalidator.h"
 #include "formelementvalidatorregex.h"
 
+enum
+{
+       PROP_0,
+       PROP_REGEX
+};
+
 static void zak_form_element_validator_regex_class_init (ZakFormElementValidatorRegexClass *class);
 static void zak_form_element_validator_regex_init (ZakFormElementValidatorRegex *zak_form_element);
 
@@ -71,6 +77,13 @@ zak_form_element_validator_regex_class_init (ZakFormElementValidatorRegexClass *
        parent_class->validate = zak_form_element_validator_regex_validate;
 
        g_type_class_add_private (object_class, sizeof (ZakFormElementValidatorRegexPrivate));
+
+       g_object_class_install_property (object_class, PROP_REGEX,
+                                        g_param_spec_string ("regex",
+                                                             "Regex",
+                                                             "Regex",
+                                                             "",
+                                                             G_PARAM_READWRITE));
 }
 
 static void
@@ -106,6 +119,20 @@ ZakFormElementValidatorRegex
  */
 gboolean
 zak_form_element_validator_regex_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode)
+{
+       zak_form_element_validator_regex_set_regex (ZAK_FORM_ELEMENT_VALIDATOR_REGEX (validator), (gchar *)xmlNodeGetContent (xnode));
+
+       return TRUE;
+}
+
+/**
+ * zak_form_element_validator_regex_set_regex:
+ * @validaotr:
+ * @regex:
+ *
+ */
+void
+zak_form_element_validator_regex_set_regex (ZakFormElementValidatorRegex *validator, const gchar *regex)
 {
        ZakFormElementValidatorRegexPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_REGEX_GET_PRIVATE (validator);
 
@@ -113,9 +140,20 @@ zak_form_element_validator_regex_xml_parsing (ZakFormElementValidator *validator
                {
                        g_free (priv->regex);
                }
-       priv->regex = g_strdup ((gchar *)xmlNodeGetContent (xnode));
+       priv->regex = g_strdup (regex);
+}
 
-       return TRUE;
+/**
+ * zak_form_element_validator_regex_get_regex:
+ * @validator:
+ *
+ */
+gchar
+*zak_form_element_validator_regex_get_regex (ZakFormElementValidatorRegex *validator)
+{
+       ZakFormElementValidatorRegexPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_REGEX_GET_PRIVATE (validator);
+
+       return g_strdup (priv->regex);
 }
 
 /* PRIVATE */
@@ -130,6 +168,10 @@ zak_form_element_validator_regex_set_property (GObject *object,
 
        switch (property_id)
                {
+               case PROP_REGEX:
+                   zak_form_element_validator_regex_set_regex (zak_form_element, g_value_dup_string (value));
+                       break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -147,6 +189,10 @@ zak_form_element_validator_regex_get_property (GObject *object,
 
        switch (property_id)
                {
+               case PROP_REGEX:
+                       g_value_set_string (value, zak_form_element_validator_regex_get_regex (zak_form_element));
+                       break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
index 3bcf0d20cf693cf851ca6db854452214a234b48a..3ed9948d096e8ef3e586119f3be086cda3c6ed7a 100644 (file)
@@ -33,9 +33,12 @@ G_BEGIN_DECLS
 #define ZAK_TYPE_FORM_ELEMENT_VALIDATOR_REGEX zak_form_element_validator_regex_get_type ()
 G_DECLARE_FINAL_TYPE (ZakFormElementValidatorRegex, zak_form_element_validator_regex, ZAK_FORM, ELEMENT_VALIDATOR_REGEX, ZakFormElementValidator)
 
-        ZakFormElementValidatorRegex *zak_form_element_validator_regex_new (void);
+ZakFormElementValidatorRegex *zak_form_element_validator_regex_new (void);
 gboolean zak_form_element_validator_regex_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
 
+void zak_form_element_validator_regex_set_regex (ZakFormElementValidatorRegex *validator, const gchar *regex);
+gchar *zak_form_element_validator_regex_get_regex (ZakFormElementValidatorRegex *validator);
+
 
 G_END_DECLS