示例#1
0
/**
 * cr_declaration_to_string:
 *@a_this: the current instance of #CRDeclaration.
 *@a_indent: the number of indentation white char
 *to put before the actual serialisation.
 *
 *Serializes the declaration into a string
 *Returns the serialized form the declaration. The caller must
 *free the string using g_free().
 */
gchar *
cr_declaration_to_string (CRDeclaration * a_this, gulong a_indent)
{
        GString *stringue = NULL;

        guchar *str = NULL,
                *result = NULL;

        g_return_val_if_fail (a_this, NULL);

	stringue = g_string_new (NULL);

	if (a_this->property 
	    && a_this->property->stryng
	    && a_this->property->stryng->str) {
		str = g_strndup (a_this->property->stryng->str,
				 a_this->property->stryng->len);
		if (str) {
			cr_utils_dump_n_chars2 (' ', stringue, 
						a_indent);
			g_string_append (stringue, str);
			g_free (str);
			str = NULL;
		} else
                        goto error;

                if (a_this->value) {
                        guchar *value_str = NULL;

                        value_str = cr_term_to_string (a_this->value);
                        if (value_str) {
                                g_string_append_printf (stringue, " : %s",
                                                        value_str);
                                g_free (value_str);
                        } else
                                goto error;
                }
                if (a_this->important == TRUE) {
                        g_string_append_printf (stringue, " %s",
                                                "!important");
                }
        }
        if (stringue && stringue->str) {
                result = stringue->str;
                g_string_free (stringue, FALSE);
        }
        return result;

      error:
        if (stringue) {
                g_string_free (stringue, TRUE);
                stringue = NULL;
        }
        if (str) {
                g_free (str);
                str = NULL;
        }

        return result;
}
示例#2
0
/**
 *Dumps the expression (a list of terms connected by operators)
 *to a file.
 *TODO: finish the dump. The dump of some type of terms have not yet been
 *implemented.
 *@param a_this the current instance of #CRTerm.
 *@param a_fp the destination file pointer.
 */
void
cr_term_dump (CRTerm * a_this, FILE * a_fp)
{
    guchar *content = NULL;

    g_return_if_fail (a_this);

    content = cr_term_to_string (a_this);

    if (content) {
        fprintf (a_fp, "%s", content);
        g_free (content);
    }
}
示例#3
0
static enum CRStatus
test_cr_term_parse_expression_from_buf (void)
{
        guchar *tmp_str = NULL;
        CRTerm *term = NULL;

        term = cr_term_parse_expression_from_buf (gv_term_buf, CR_UTF_8);

        if (!term)
                return CR_ERROR;
        tmp_str = cr_term_to_string (term);
        if (term) {
                cr_term_destroy (term);
                term = NULL;
        }
        if (tmp_str) {
                g_free (tmp_str);
                tmp_str = NULL;
        }
        return CR_OK;
}
示例#4
0
guchar *
cr_term_one_to_string (CRTerm * a_this)
{
    GString *str_buf = 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);

    if ((a_this->content.str == NULL)
            && (a_this->content.num == NULL)
            && (a_this->content.str == NULL)
            && (a_this->content.rgb == NULL))
        return NULL ;

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

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

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

        break;
    }

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

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

    default:
        break;
    }

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

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

        break;

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

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

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

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

                if (tmp_str) {
                    g_string_append_printf
                    (str_buf,
                     "%s", tmp_str);
                    g_free (tmp_str);
                    tmp_str = NULL;
                }

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

        break;

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

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

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

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

    case TERM_URI:
        if (a_this->content.str) {
            content = g_strndup
                      (a_this->content.str->stryng->str,
                       a_this->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 (a_this->content.rgb) {

            g_string_append_printf (str_buf, "rgb(");
            gchar *tmp_str = (gchar *)cr_rgb_to_string (a_this->content.rgb);

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

        break;

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

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

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

    default:
        g_string_append_printf (str_buf,
                                "%s",
                                "Unrecognized Term type");
        break;
    }

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

    return result;
}