From: Andrea Zagli Date: Wed, 6 Jan 2016 10:31:26 +0000 (+0100) Subject: Added property ZakFormElementValidatorNotempty::as_empty_string. X-Git-Tag: debian/0.0.1-1~10 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=13473655fe817c239907b19eb6cf8bc3220a9e70;p=zakform%2Flibzakform Added property ZakFormElementValidatorNotempty::as_empty_string. --- diff --git a/src/formelementvalidatornotempty.c b/src/formelementvalidatornotempty.c index 343e2ab..1de3f30 100644 --- a/src/formelementvalidatornotempty.c +++ b/src/formelementvalidatornotempty.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Andrea Zagli + * Copyright (C) 2015-2016 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -52,7 +52,7 @@ struct _ZakFormElementValidatorNotempty typedef struct _ZakFormElementValidatorNotemptyPrivate ZakFormElementValidatorNotemptyPrivate; struct _ZakFormElementValidatorNotemptyPrivate { - gpointer nothing; + gchar *as_empty_string; }; G_DEFINE_TYPE (ZakFormElementValidatorNotempty, zak_form_element_validator_notempty, ZAK_FORM_TYPE_ELEMENT_VALIDATOR) @@ -77,6 +77,8 @@ static void zak_form_element_validator_notempty_init (ZakFormElementValidatorNotempty *zak_form_element) { ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (zak_form_element); + + priv->as_empty_string = g_strdup (""); } /** @@ -101,9 +103,16 @@ ZakFormElementValidatorNotempty * */ gboolean -zak_form_elemen_validator_notempty_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode) +zak_form_element_validator_notempty_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode) { - /* nothing to do */ + ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (validator); + + if (priv->as_empty_string != NULL) + { + g_free (priv->as_empty_string); + } + priv->as_empty_string = g_strdup ((gchar *)xmlNodeGetContent (xnode)); + return TRUE; } @@ -114,8 +123,8 @@ zak_form_element_validator_notempty_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - ZakFormElementValidatorNotempty *zak_form_element = (ZakFormElementValidatorNotempty *)object; - ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (zak_form_element); + ZakFormElementValidatorNotempty *validator = (ZakFormElementValidatorNotempty *)object; + ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (validator); switch (property_id) { @@ -131,8 +140,8 @@ zak_form_element_validator_notempty_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - ZakFormElementValidatorNotempty *zak_form_element = (ZakFormElementValidatorNotempty *)object; - ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (zak_form_element); + ZakFormElementValidatorNotempty *validator = (ZakFormElementValidatorNotempty *)object; + ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (validator); switch (property_id) { @@ -145,8 +154,8 @@ zak_form_element_validator_notempty_get_property (GObject *object, static void zak_form_element_validator_notempty_dispose (GObject *gobject) { - ZakFormElementValidatorNotempty *zak_form_element = (ZakFormElementValidatorNotempty *)gobject; - ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (zak_form_element); + ZakFormElementValidatorNotempty *validator = (ZakFormElementValidatorNotempty *)gobject; + ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (validator); @@ -157,8 +166,8 @@ zak_form_element_validator_notempty_dispose (GObject *gobject) static void zak_form_element_validator_notempty_finalize (GObject *gobject) { - ZakFormElementValidatorNotempty *zak_form_element = (ZakFormElementValidatorNotempty *)gobject; - ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (zak_form_element); + ZakFormElementValidatorNotempty *validator = (ZakFormElementValidatorNotempty *)gobject; + ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (validator); @@ -167,14 +176,16 @@ zak_form_element_validator_notempty_finalize (GObject *gobject) } static gboolean -zak_form_element_validator_notempty_validate (ZakFormElementValidator *validator_notempty, +zak_form_element_validator_notempty_validate (ZakFormElementValidator *validator, const gchar *value) { gboolean ret; + ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (validator); + g_return_val_if_fail (value != NULL, FALSE); - ret = (g_strcmp0 (value, "") != 0); + ret = (g_strcmp0 (value, priv->as_empty_string) != 0); return ret; } diff --git a/src/formelementvalidatorregex.c b/src/formelementvalidatorregex.c index 17db5eb..1cf81be 100644 --- a/src/formelementvalidatorregex.c +++ b/src/formelementvalidatorregex.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Andrea Zagli + * Copyright (C) 2015-2016 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -83,12 +83,11 @@ zak_form_element_validator_regex_init (ZakFormElementValidatorRegex *zak_form_el /** * zak_form_element_validator_regex_new: - * @regex: * * Returns: the newly created #ZakFormElementValidatorRegex object. */ ZakFormElementValidatorRegex -*zak_form_element_validator_regex_new (const gchar *regex) +*zak_form_element_validator_regex_new () { ZakFormElementValidatorRegex *zak_form_element_validator_regex; @@ -96,11 +95,6 @@ ZakFormElementValidatorRegex ZakFormElementValidatorRegexPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_REGEX_GET_PRIVATE (zak_form_element_validator_regex); - if (regex != NULL) - { - priv->regex = g_strdup (regex); - } - return zak_form_element_validator_regex; } diff --git a/src/formelementvalidatorregex.h b/src/formelementvalidatorregex.h index d59f91e..3bcf0d2 100644 --- a/src/formelementvalidatorregex.h +++ b/src/formelementvalidatorregex.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Andrea Zagli + * Copyright (C) 2015-2016 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,7 +33,7 @@ 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 (const gchar *regex); + ZakFormElementValidatorRegex *zak_form_element_validator_regex_new (void); gboolean zak_form_element_validator_regex_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);