From a051bb7e0e7cb408c99508c00f50b2093d3702c0 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 5 Oct 2015 19:42:56 +0200 Subject: [PATCH] Added ZakCgiFormElementFilterTrim. --- src/Makefile.am | 2 + src/formelementfiltertrim.c | 159 ++++++++++++++++++++++++++++++++++++ src/formelementfiltertrim.h | 44 ++++++++++ src/formelementifilter.c | 6 +- src/formelementifilter.h | 4 +- 5 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 src/formelementfiltertrim.c create mode 100644 src/formelementfiltertrim.h diff --git a/src/Makefile.am b/src/Makefile.am index 50aa5fa..a4c1564 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,7 @@ libzakcgi_la_SOURCES = commons.c \ formelementtextarea.c \ formelementsubmit.c \ formelementifilter.c \ + formelementfiltertrim.c \ main.c \ session.c \ tag.c \ @@ -38,6 +39,7 @@ libzakcgi_include_HEADERS = \ formelementtextarea.h \ formelementsubmit.h \ formelementifilter.h \ + formelementfiltertrim.h \ main.h \ session.h \ tag.h \ diff --git a/src/formelementfiltertrim.c b/src/formelementfiltertrim.c new file mode 100644 index 0000000..d8928ca --- /dev/null +++ b/src/formelementfiltertrim.c @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "formelementifilter.h" +#include "formelementfiltertrim.h" + +static void zak_cgi_form_element_filter_trim_class_init (ZakCgiFormElementFilterTrimClass *class); +static void zak_cgi_form_element_filter_trim_interface_init (ZakCgiFormElementIFilterInterface *iface); +static void zak_cgi_form_element_filter_trim_init (ZakCgiFormElementFilterTrim *zak_cgi_form_element); + +static void zak_cgi_form_element_filter_trim_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void zak_cgi_form_element_filter_trim_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void zak_cgi_form_element_filter_trim_dispose (GObject *gobject); +static void zak_cgi_form_element_filter_trim_finalize (GObject *gobject); + +static gchar *zak_cgi_form_element_filter_trim_filter (ZakCgiFormElementFilterTrim *filter_trim, const gchar *value); + +struct _ZakCgiFormElementFilterTrim +{ + GObject parent_instance; + + /* Other members, including private data. */ +}; + +#define ZAK_CGI_FORM_ELEMENT_FILTER_TRIM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_FILTER_TRIM, ZakCgiFormElementFilterTrimPrivate)) + +typedef struct _ZakCgiFormElementFilterTrimPrivate ZakCgiFormElementFilterTrimPrivate; +struct _ZakCgiFormElementFilterTrimPrivate + { + gpointer nothing; + }; + +G_DEFINE_TYPE_WITH_CODE (ZakCgiFormElementFilterTrim, zak_cgi_form_element_filter_trim, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (ZAK_CGI_TYPE_FORM_ELEMENT_IFILTER, + zak_cgi_form_element_filter_trim_interface_init)) + +static void +zak_cgi_form_element_filter_trim_class_init (ZakCgiFormElementFilterTrimClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->set_property = zak_cgi_form_element_filter_trim_set_property; + object_class->get_property = zak_cgi_form_element_filter_trim_get_property; + object_class->dispose = zak_cgi_form_element_filter_trim_dispose; + object_class->finalize = zak_cgi_form_element_filter_trim_finalize; + + g_type_class_add_private (object_class, sizeof (ZakCgiFormElementFilterTrimPrivate)); +} + +static void +zak_cgi_form_element_filter_trim_interface_init (ZakCgiFormElementIFilterInterface *iface) +{ + iface->filter = zak_cgi_form_element_filter_trim_filter; +} + +static void +zak_cgi_form_element_filter_trim_init (ZakCgiFormElementFilterTrim *zak_cgi_form_element) +{ + ZakCgiFormElementFilterTrimPrivate *priv = ZAK_CGI_FORM_ELEMENT_FILTER_TRIM_GET_PRIVATE (zak_cgi_form_element); +} + +/* PRIVATE */ +static void +zak_cgi_form_element_filter_trim_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + ZakCgiFormElementFilterTrim *zak_cgi_form_element = (ZakCgiFormElementFilterTrim *)object; + ZakCgiFormElementFilterTrimPrivate *priv = ZAK_CGI_FORM_ELEMENT_FILTER_TRIM_GET_PRIVATE (zak_cgi_form_element); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +zak_cgi_form_element_filter_trim_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + ZakCgiFormElementFilterTrim *zak_cgi_form_element = (ZakCgiFormElementFilterTrim *)object; + ZakCgiFormElementFilterTrimPrivate *priv = ZAK_CGI_FORM_ELEMENT_FILTER_TRIM_GET_PRIVATE (zak_cgi_form_element); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +zak_cgi_form_element_filter_trim_dispose (GObject *gobject) +{ + ZakCgiFormElementFilterTrim *zak_cgi_form_element = (ZakCgiFormElementFilterTrim *)gobject; + ZakCgiFormElementFilterTrimPrivate *priv = ZAK_CGI_FORM_ELEMENT_FILTER_TRIM_GET_PRIVATE (zak_cgi_form_element); + + + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->dispose (gobject); +} + +static void +zak_cgi_form_element_filter_trim_finalize (GObject *gobject) +{ + ZakCgiFormElementFilterTrim *zak_cgi_form_element = (ZakCgiFormElementFilterTrim *)gobject; + ZakCgiFormElementFilterTrimPrivate *priv = ZAK_CGI_FORM_ELEMENT_FILTER_TRIM_GET_PRIVATE (zak_cgi_form_element); + + + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->finalize (gobject); +} + +static gchar +*zak_cgi_form_element_filter_trim_filter (ZakCgiFormElementFilterTrim *filter_trim, + const gchar *value) +{ + gchar *ret; + + g_return_val_if_fail (value != NULL, g_strdup ("")); + + ret = g_strdup (value); + g_strstrip (ret); + + return ret;; +} diff --git a/src/formelementfiltertrim.h b/src/formelementfiltertrim.h new file mode 100644 index 0000000..e9a4152 --- /dev/null +++ b/src/formelementfiltertrim.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __ZAK_CGI_FORM_ELEMENT_FILTER_TRIM_H__ +#define __ZAK_CGI_FORM_ELEMENT_FILTER_TRIM_H__ + + +#include + + +G_BEGIN_DECLS + + +/* + * Type declaration. + */ +#define ZAK_CGI_TYPE_FORM_ELEMENT_FILTER_TRIM zak_cgi_form_element_filter_trim_get_type () +G_DECLARE_FINAL_TYPE (ZakCgiFormElementFilterTrim, zak_cgi_form_element_filter_trim, ZAK_CGI, FORM_ELEMENT_FILTER_TRIM, GObject) + +/* + * Method definitions. + */ +ZakCgiFormElementFilterTrim *zak_cgi_form_element_filter_trim_new (void); + + +G_END_DECLS + + +#endif /* __ZAK_CGI_FORM_ELEMENT_FILTER_TRIM_H__ */ diff --git a/src/formelementifilter.c b/src/formelementifilter.c index 00e0305..0948e41 100644 --- a/src/formelementifilter.c +++ b/src/formelementifilter.c @@ -26,10 +26,10 @@ zak_cgi_form_element_ifilter_default_init (ZakCgiFormElementIFilterInterface *if /* add properties and signals to the interface here */ } -void -zak_cgi_form_element_ifilter_filter (ZakCgiFormElementIFilter *self) +gchar +*zak_cgi_form_element_ifilter_filter (ZakCgiFormElementIFilter *self, const gchar *value) { g_return_if_fail (ZAK_CGI_IS_FORM_ELEMENT_IFILTER (self)); - ZAK_CGI_FORM_ELEMENT_IFILTER_GET_IFACE (self)->filter (self); + return ZAK_CGI_FORM_ELEMENT_IFILTER_GET_IFACE (self)->filter (self, value); } diff --git a/src/formelementifilter.h b/src/formelementifilter.h index 07b264c..fcd4ef7 100644 --- a/src/formelementifilter.h +++ b/src/formelementifilter.h @@ -32,10 +32,10 @@ struct _ZakCgiFormElementIFilterInterface { GTypeInterface parent_iface; - void (*filter) (ZakCgiFormElementIFilter *self); + gchar *(*filter) (ZakCgiFormElementIFilter *self, const gchar *value); }; -void zak_cgi_form_element_ifilter_filter (ZakCgiFormElementIFilter *self); +gchar *zak_cgi_form_element_ifilter_filter (ZakCgiFormElementIFilter *self, const gchar *value); G_END_DECLS -- 2.49.0