Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

CRDeclaration* cr_declaration_parse_list_from_buf ( const guchar *  a_str,
enum CREncoding  a_enc 
)

Parses a ';' separated list of properties declaration.

Parameters:
a_str the input buffer that contains the list of declaration to parse.
a_enc the encoding of a_str
Returns:
the parsed list of declaration, NULL if parsing failed.

Definition at line 166 of file cr-declaration.c.

References cr_declaration_append(), cr_declaration_destroy(), cr_declaration_new(), cr_parser_destroy(), cr_parser_get_tknzr(), cr_parser_new_from_buf(), cr_parser_parse_declaration(), cr_parser_try_to_skip_spaces_and_comments(), cr_term_destroy(), cr_tknzr_peek_char(), and cr_tknzr_read_char().

Referenced by sp_style_merge_from_style_string().

{

        enum CRStatus status = CR_OK;
        CRTerm *value = NULL;
        CRString *property = NULL;
        CRDeclaration *result = NULL,
                *cur_decl = NULL;
        CRTknzr *tokenizer = NULL;
        gboolean important = FALSE;

        g_return_val_if_fail (a_str, NULL);

        CRParser *parser = (CRParser *)cr_parser_new_from_buf
                  ((guchar*)a_str, strlen ((char *)a_str), a_enc, FALSE);
        g_return_val_if_fail (parser, NULL);
        status = cr_parser_get_tknzr (parser, &tokenizer);
        if (status != CR_OK || !tokenizer) {
                if (status == CR_OK)
                        status = CR_ERROR;
                goto cleanup;
        }
        status = cr_parser_try_to_skip_spaces_and_comments (parser);
        if (status != CR_OK)
                goto cleanup;

        status = cr_parser_parse_declaration (parser, &property,
                                              &value, &important);
        if (status != CR_OK || !property) {
                if (status != CR_OK)
                        status = CR_ERROR;
                goto cleanup;
        }
        result = cr_declaration_new (NULL, property, value);
        if (result) {
                property = NULL;
                value = NULL;
                result->important = important;
        }
        /*now, go parse the other declarations */
        for (;;) {
                guint32 c = 0;

                cr_parser_try_to_skip_spaces_and_comments (parser);
                status = cr_tknzr_peek_char (tokenizer, &c);
                if (status != CR_OK) {
                        if (status == CR_END_OF_INPUT_ERROR) 
                                status = CR_OK;
                        goto cleanup;
                }
                if (c == ';') {
                        status = cr_tknzr_read_char (tokenizer, &c);
                } else {
                        cr_tknzr_read_char (tokenizer, &c);
                        continue; // try to keep reading until we reach the end or a ;
                }
                important = FALSE;
                cr_parser_try_to_skip_spaces_and_comments (parser);
                status = cr_parser_parse_declaration (parser, &property,
                                                      &value, &important);
                if (status != CR_OK || !property) {
                        if (status == CR_END_OF_INPUT_ERROR) {
                                status = CR_OK; // simply the end of input, do not delete what we got so far, just finish
                                break; 
                        } else {
                                continue; // even if one declaration is broken, it's no reason to discard others (see http://www.w3.org/TR/CSS21/syndata.html#declaration)
                                                }
                }
                cur_decl = cr_declaration_new (NULL, property, value);
                if (cur_decl) {
                        cur_decl->important = important;
                        result = cr_declaration_append (result, cur_decl);
                        property = NULL;
                        value = NULL;
                        cur_decl = NULL;
                } else {
                        break;
                }
        }

      cleanup:

        if (parser) {
                cr_parser_destroy (parser);
                parser = NULL;
        }

        if (property) {
                cr_string_destroy (property);
                property = NULL;
        }

        if (value) {
                cr_term_destroy (value);
                value = NULL;
        }

        if (status != CR_OK && result) {
                cr_declaration_destroy (result);
                result = NULL;
        }
        return result;
}


Generated by  Doxygen 1.6.0   Back to index