1 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
4 * This file is part of The Croco Library
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2.1 of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * See COPYRIGHTS file for copyrights information.
25 #include "cr-attr-sel.h"
30 * #CRAdditionalSel abstracts an attribute selector.
31 * Attributes selectors are described in the css2 spec [5.8].
32 * There are more generally used in the css2 selectors described in
38 * The constructor of #CRAttrSel.
39 * Returns the newly allocated instance
43 cr_attr_sel_new (void)
45 CRAttrSel *result = NULL;
47 result = g_malloc0 (sizeof (CRAttrSel));
53 * cr_attr_sel_append_attr_sel:
54 * @a_this: the this pointer of the current instance of #CRAttrSel.
55 * @a_attr_sel: selector to append.
57 * Appends an attribute selector to the current list of
58 * attribute selectors represented by a_this.
59 * Returns CR_OK upon successfull completion, an error code otherwise.
62 cr_attr_sel_append_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel)
64 CRAttrSel *cur_sel = NULL;
66 g_return_val_if_fail (a_this && a_attr_sel,
69 for (cur_sel = a_this;
71 cur_sel = cur_sel->next) ;
73 cur_sel->next = a_attr_sel;
74 a_attr_sel->prev = cur_sel;
80 * cr_attr_sel_prepend_attr_sel:
81 *@a_this: the "this pointer" of the current instance *of #CRAttrSel.
82 *@a_attr_sel: the attribute selector to append.
84 *Prepends an attribute selector to the list of
85 *attributes selector represented by a_this.
86 *Returns CR_OK upon successfull completion, an error code otherwise.
89 cr_attr_sel_prepend_attr_sel (CRAttrSel * a_this,
90 CRAttrSel * a_attr_sel)
92 g_return_val_if_fail (a_this && a_attr_sel,
95 a_attr_sel->next = a_this;
96 a_this->prev = a_attr_sel;
102 * cr_attr_sel_to_string:
103 * @a_this: the current instance of #CRAttrSel.
105 * Serializes an attribute selector into a string
106 * Returns the serialized attribute selector.
109 cr_attr_sel_to_string (CRAttrSel * a_this)
111 CRAttrSel *cur = NULL;
112 guchar *result = NULL;
113 GString *str_buf = NULL;
115 g_return_val_if_fail (a_this, NULL);
117 str_buf = g_string_new (NULL);
119 for (cur = a_this; cur; cur = cur->next) {
121 g_string_append_c (str_buf, ' ');
127 name = g_strndup (cur->name->stryng->str,
128 cur->name->stryng->len);
130 g_string_append (str_buf, name);
137 guchar *value = NULL;
139 value = g_strndup (cur->value->stryng->str,
140 cur->value->stryng->len);
142 switch (cur->match_way) {
147 g_string_append_c (str_buf, '=');
151 g_string_append (str_buf, "~=");
155 g_string_append (str_buf, "|=");
162 g_string_append_printf
163 (str_buf, "\"%s\"", value);
172 result = str_buf->str;
173 g_string_free (str_buf, FALSE);
181 * @a_this: the "this pointer" of the current instance of
183 * @a_fp: the destination file.
185 * Dumps the current instance of #CRAttrSel to a file.
188 cr_attr_sel_dump (CRAttrSel * a_this, FILE * a_fp)
190 guchar *tmp_str = NULL;
192 g_return_if_fail (a_this);
194 tmp_str = cr_attr_sel_to_string (a_this);
197 fprintf (a_fp, "%s", tmp_str);
204 *cr_attr_sel_destroy:
205 *@a_this: the "this pointer" of the current
206 *instance of #CRAttrSel.
208 *Destroys the current instance of #CRAttrSel.
209 *Frees all the fields if they are non null.
212 cr_attr_sel_destroy (CRAttrSel * a_this)
214 g_return_if_fail (a_this);
217 cr_string_destroy (a_this->name);
222 cr_string_destroy (a_this->value);
223 a_this->value = NULL;
227 cr_attr_sel_destroy (a_this->next);