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 * Author: Dodji Seketeli
21 * see COPYRIGHTS file for copyright information.
26 *The definition of the #CRToken class.
27 *Abstracts a css2 token.
33 *TODO: write a CRToken::to_string() method.
37 *Frees the attributes of the current instance
39 *@param a_this the current instance of #CRToken.
42 cr_token_clear (CRToken * a_this)
44 g_return_if_fail (a_this);
46 switch (a_this->type) {
54 case FONT_FACE_SYM_TK:
57 case IMPORTANT_SYM_TK:
75 cr_string_destroy (a_this->u.str);
91 cr_num_destroy (a_this->u.num);
98 cr_num_destroy (a_this->u.num);
103 cr_string_destroy (a_this->dimen);
104 a_this->dimen = NULL;
111 cr_rgb_destroy (a_this->u.rgb) ;
112 a_this->u.rgb = NULL ;
116 case UNICODERANGE_TK:
117 /*not supported yet. */
121 cr_utils_trace_info ("I don't know how to clear this token\n") ;
125 a_this->type = NO_TK;
129 *Default constructor of
131 *@return the newly built instance of #CRToken.
136 CRToken *result = NULL;
138 result = g_try_malloc (sizeof (CRToken));
140 if (result == NULL) {
141 cr_utils_trace_info ("Out of memory");
145 memset (result, 0, sizeof (CRToken));
151 *Sets the type of curren instance of
152 *#CRToken to 'S_TK' (S in the css2 spec)
153 *@param a_this the current instance of #CRToken.
154 *@return CR_OK upon successfull completion, an error
158 cr_token_set_s (CRToken * a_this)
160 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
162 cr_token_clear (a_this);
170 *Sets the type of the current instance of
171 *#CRToken to 'CDO_TK' (CDO as said by the css2 spec)
172 *@param a_this the current instance of #CRToken.
173 *@return CR_OK upon successfull completion, an error
177 cr_token_set_cdo (CRToken * a_this)
179 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
181 cr_token_clear (a_this);
183 a_this->type = CDO_TK;
189 *Sets the type of the current token to
190 *CDC_TK (CDC as said by the css2 spec).
191 *@param a_this the current instance of #CRToken.
192 *@return CR_OK upon successfull completion, an error
196 cr_token_set_cdc (CRToken * a_this)
198 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
200 cr_token_clear (a_this);
202 a_this->type = CDC_TK;
208 *Sets the type of the current instance of
209 *#CRToken to INCLUDES_TK (INCLUDES as said by the css2 spec).
210 *@param a_this the current instance of #CRToken.
211 *@return CR_OK upon successfull completion, an error
215 cr_token_set_includes (CRToken * a_this)
217 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
219 cr_token_clear (a_this);
221 a_this->type = INCLUDES_TK;
227 *Sets the type of the current instance of
228 *#CRToken to DASHMATCH_TK (DASHMATCH as said by the css2 spec).
229 *@param a_this the current instance of #CRToken.
230 *@return CR_OK upon successfull completion, an error
234 cr_token_set_dashmatch (CRToken * a_this)
236 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
238 cr_token_clear (a_this);
240 a_this->type = DASHMATCH_TK;
246 cr_token_set_comment (CRToken * a_this, CRString * a_str)
248 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
250 cr_token_clear (a_this);
251 a_this->type = COMMENT_TK;
252 a_this->u.str = a_str ;
257 cr_token_set_string (CRToken * a_this, CRString * a_str)
259 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
261 cr_token_clear (a_this);
263 a_this->type = STRING_TK;
265 a_this->u.str = a_str ;
271 cr_token_set_ident (CRToken * a_this, CRString * a_ident)
273 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
275 cr_token_clear (a_this);
276 a_this->type = IDENT_TK;
277 a_this->u.str = a_ident;
283 cr_token_set_function (CRToken * a_this, CRString * a_fun_name)
285 g_return_val_if_fail (a_this,
288 cr_token_clear (a_this);
289 a_this->type = FUNCTION_TK;
290 a_this->u.str = a_fun_name;
295 cr_token_set_hash (CRToken * a_this, CRString * a_hash)
297 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
299 cr_token_clear (a_this);
300 a_this->type = HASH_TK;
301 a_this->u.str = a_hash;
307 cr_token_set_rgb (CRToken * a_this, CRRgb * a_rgb)
309 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
311 cr_token_clear (a_this);
312 a_this->type = RGB_TK;
313 a_this->u.rgb = a_rgb;
319 cr_token_set_import_sym (CRToken * a_this)
321 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
323 cr_token_clear (a_this);
325 a_this->type = IMPORT_SYM_TK;
331 cr_token_set_page_sym (CRToken * a_this)
333 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
335 cr_token_clear (a_this);
337 a_this->type = PAGE_SYM_TK;
343 cr_token_set_media_sym (CRToken * a_this)
345 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
347 cr_token_clear (a_this);
349 a_this->type = MEDIA_SYM_TK;
355 cr_token_set_font_face_sym (CRToken * a_this)
357 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
359 cr_token_clear (a_this);
360 a_this->type = FONT_FACE_SYM_TK;
366 cr_token_set_charset_sym (CRToken * a_this)
368 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
370 cr_token_clear (a_this);
371 a_this->type = CHARSET_SYM_TK;
377 cr_token_set_atkeyword (CRToken * a_this, CRString * a_atname)
379 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
381 cr_token_clear (a_this);
382 a_this->type = ATKEYWORD_TK;
383 a_this->u.str = a_atname;
388 cr_token_set_important_sym (CRToken * a_this)
390 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
391 cr_token_clear (a_this);
392 a_this->type = IMPORTANT_SYM_TK;
397 cr_token_set_ems (CRToken * a_this, CRNum * a_num)
399 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
400 cr_token_clear (a_this);
401 a_this->type = EMS_TK;
402 a_this->u.num = a_num;
407 cr_token_set_exs (CRToken * a_this, CRNum * a_num)
409 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
410 cr_token_clear (a_this);
411 a_this->type = EXS_TK;
412 a_this->u.num = a_num;
417 cr_token_set_length (CRToken * a_this, CRNum * a_num,
418 enum CRTokenExtraType a_et)
420 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
422 cr_token_clear (a_this);
424 a_this->type = LENGTH_TK;
425 a_this->extra_type = a_et;
426 a_this->u.num = a_num;
432 cr_token_set_angle (CRToken * a_this, CRNum * a_num,
433 enum CRTokenExtraType a_et)
435 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
437 cr_token_clear (a_this);
439 a_this->type = ANGLE_TK;
440 a_this->extra_type = a_et;
441 a_this->u.num = a_num;
447 cr_token_set_time (CRToken * a_this, CRNum * a_num,
448 enum CRTokenExtraType a_et)
450 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
452 cr_token_clear (a_this);
454 a_this->type = TIME_TK;
455 a_this->extra_type = a_et;
456 a_this->u.num = a_num;
462 cr_token_set_freq (CRToken * a_this, CRNum * a_num,
463 enum CRTokenExtraType a_et)
465 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
467 cr_token_clear (a_this);
469 a_this->type = FREQ_TK;
470 a_this->extra_type = a_et;
471 a_this->u.num = a_num;
477 cr_token_set_dimen (CRToken * a_this, CRNum * a_num,
480 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
481 cr_token_clear (a_this);
482 a_this->type = DIMEN_TK;
483 a_this->u.num = a_num;
484 a_this->dimen = a_dim;
490 cr_token_set_percentage (CRToken * a_this, CRNum * a_num)
492 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
494 cr_token_clear (a_this);
496 a_this->type = PERCENTAGE_TK;
497 a_this->u.num = a_num;
503 cr_token_set_number (CRToken * a_this, CRNum * a_num)
505 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
507 cr_token_clear (a_this);
509 a_this->type = NUMBER_TK;
510 a_this->u.num = a_num;
515 cr_token_set_uri (CRToken * a_this, CRString * a_uri)
517 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
519 cr_token_clear (a_this);
521 a_this->type = URI_TK;
522 a_this->u.str = a_uri;
528 cr_token_set_delim (CRToken * a_this, guint32 a_char)
530 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
532 cr_token_clear (a_this);
534 a_this->type = DELIM_TK;
535 a_this->u.unichar = a_char;
541 cr_token_set_semicolon (CRToken * a_this)
543 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
545 cr_token_clear (a_this);
547 a_this->type = SEMICOLON_TK;
553 cr_token_set_cbo (CRToken * a_this)
555 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
557 cr_token_clear (a_this);
559 a_this->type = CBO_TK;
565 cr_token_set_cbc (CRToken * a_this)
567 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
569 cr_token_clear (a_this);
571 a_this->type = CBC_TK;
577 cr_token_set_po (CRToken * a_this)
579 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
581 cr_token_clear (a_this);
583 a_this->type = PO_TK;
589 cr_token_set_pc (CRToken * a_this)
591 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
593 cr_token_clear (a_this);
595 a_this->type = PC_TK;
601 cr_token_set_bo (CRToken * a_this)
603 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
605 cr_token_clear (a_this);
607 a_this->type = BO_TK;
613 cr_token_set_bc (CRToken * a_this)
615 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
617 cr_token_clear (a_this);
619 a_this->type = BC_TK;
625 *The destructor of the #CRToken class.
626 *@param a_this the current instance of #CRToken.
629 cr_token_destroy (CRToken * a_this)
631 g_return_if_fail (a_this);
633 cr_token_clear (a_this);