Logo Search packages:      
Sourcecode: inkscape version File versions

guchar* cr_term_to_string ( CRTerm a_this  ) 

Serializes the expression represented by the chained instances of CRterm.

Parameters:
a_this the current instance of CRTerm
Returns:
the zero terminated string containing the serialized form of CRTerm. MUST BE FREED BY THE CALLER using g_free().

Definition at line 278 of file cr-term.c.

References _CRTerm::content, cr_num_to_string(), cr_term_to_string(), _CRTerm::ext_content, _CRTerm::func_param, _CRTerm::next, _CRTerm::num, _CRTerm::prev, _CRTerm::rgb, _CRTerm::str, _CRTerm::the_operator, _CRTerm::type, and _CRTerm::unary_op.

Referenced by cr_declaration_to_string(), cr_term_dump(), cr_term_to_string(), and sp_style_merge_style_from_decl().

{
        GString *str_buf = NULL;
        CRTerm *cur = NULL;
        guchar *result = NULL;
        gchar *content = NULL;

        g_return_val_if_fail (a_this, NULL);

        str_buf = g_string_new (NULL);
        g_return_val_if_fail (str_buf, NULL);

        for (cur = a_this; cur; cur = cur->next) {
                if ((cur->content.str == NULL)
                    && (cur->content.num == NULL)
                    && (cur->content.str == NULL)
                    && (cur->content.rgb == NULL))
                        continue;

                switch (cur->the_operator) {
                case DIVIDE:
                        g_string_append (str_buf, " / ");
                        break;

                case COMMA:
                        g_string_append (str_buf, ", ");
                        break;

                case NO_OP:
                        if (cur->prev) {
                                g_string_append (str_buf, " ");
                        }
                        break;
                default:

                        break;
                }

                switch (cur->unary_op) {
                case PLUS_UOP:
                        g_string_append (str_buf, "+");
                        break;

                case MINUS_UOP:
                        g_string_append (str_buf, "-");
                        break;

                default:
                        break;
                }

                switch (cur->type) {
                case TERM_NUMBER:
                        if (cur->content.num) {
                                content = (gchar *)cr_num_to_string (cur->content.num);
                        }

                        if (content) {
                                g_string_append (str_buf, content);
                                g_free (content);
                                content = NULL;
                        }

                        break;

                case TERM_FUNCTION:
                        if (cur->content.str) {
                                content = g_strndup
                                        (cur->content.str->stryng->str,
                                         cur->content.str->stryng->len);
                        }

                        if (content) {
                                g_string_append_printf (str_buf, "%s(",
                                                        content);

                                if (cur->ext_content.func_param) {
                                        guchar *tmp_str = NULL;

                                        tmp_str = cr_term_to_string
                                                (cur->
                                                 ext_content.func_param);

                                        if (tmp_str) {
                                                g_string_append (str_buf, 
                                                                    (gchar *)tmp_str);
                                                g_free (tmp_str);
                                                tmp_str = NULL;
                                        }

                                        g_free (content);
                                        content = NULL;
                                }
                                g_string_append (str_buf, ")");
                        }

                        break;

                case TERM_STRING:
                        if (cur->content.str) {
                                content = g_strndup
                                        (cur->content.str->stryng->str,
                                         cur->content.str->stryng->len);
                        }

                        if (content) {
                                g_string_append_printf (str_buf,
                                                        "\"%s\"", content);
                                g_free (content);
                                content = NULL;
                        }
                        break;

                case TERM_IDENT:
                        if (cur->content.str) {
                                content = g_strndup
                                        (cur->content.str->stryng->str,
                                         cur->content.str->stryng->len);
                        }

                        if (content) {
                                g_string_append (str_buf, content);
                                g_free (content);
                                content = NULL;
                        }
                        break;

                case TERM_URI:
                        if (cur->content.str) {
                                content = g_strndup
                                          (cur->content.str->stryng->str,
                                           cur->content.str->stryng->len);
                        }

                        if (content) {
                                g_string_append_printf
                                        (str_buf, "url(%s)", content);
                                g_free (content);
                                content = NULL;
                        }
                        break;

                case TERM_RGB:
                        if (cur->content.rgb) {
                                guchar *tmp_str = NULL;

                                g_string_append (str_buf, "rgb(");
                                tmp_str = cr_rgb_to_string (cur->content.rgb);

                                if (tmp_str) {
                                        g_string_append (str_buf, (gchar *)tmp_str);
                                        g_free (tmp_str);
                                        tmp_str = NULL;
                                }
                                g_string_append (str_buf, ")");
                        }

                        break;

                case TERM_UNICODERANGE:
                        g_string_append
                                (str_buf,
                                 "?found unicoderange: dump not supported yet?");
                        break;

                case TERM_HASH:
                        if (cur->content.str) {
                                content = g_strndup
                                        (cur->content.str->stryng->str,
                                         cur->content.str->stryng->len);
                        }

                        if (content) {
                                g_string_append_printf (str_buf,
                                                        "#%s", content);
                                g_free (content);
                                content = NULL;
                        }
                        break;

                default:
                        g_string_append (str_buf,
                                         "Unrecognized Term type");
                        break;
                }
        }

        if (str_buf) {
                result = (guchar *)str_buf->str;
                g_string_free (str_buf, FALSE);
                str_buf = NULL;
        }

        return result;
}


Generated by  Doxygen 1.6.0   Back to index