From: Andrea Zagli Date: Sat, 30 Jan 2016 08:54:38 +0000 (+0100) Subject: Added get/set_regex to ZakFormValidatorRegex. X-Git-Tag: debian/0.0.1-1~9 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=42c9d388bd78324ff4fa9ece24829724292106c9;p=zakform%2Flibzakform Added get/set_regex to ZakFormValidatorRegex. --- diff --git a/src/formelementvalidatorregex.c b/src/formelementvalidatorregex.c index 1cf81be..cd92203 100644 --- a/src/formelementvalidatorregex.c +++ b/src/formelementvalidatorregex.c @@ -23,6 +23,12 @@ #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; diff --git a/src/formelementvalidatorregex.h b/src/formelementvalidatorregex.h index 3bcf0d2..3ed9948 100644 --- a/src/formelementvalidatorregex.h +++ b/src/formelementvalidatorregex.h @@ -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