summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@src.gnome.org>2003-06-09 18:09:44 +0000
committerDodji Seketeli <dodji@src.gnome.org>2003-06-09 18:09:44 +0000
commit400f3b108f7e00c1a3189fed728581df8ed8dce7 (patch)
tree1391087cfa2a00a0eed54c51d97d86a6281ea963
parentdbe4c464a5e2079fa21f05ad74fe36c93cb64670 (diff)
downloadlibcroco-400f3b108f7e00c1a3189fed728581df8ed8dce7.tar.gz
updated this test to test the new cr_declaration_to_string () api.
* tests/test4-main.c: updated this test to test the new cr_declaration_to_string () api. * src/parser/cr-declaration.[ch] (cr_declaration_to_string ()): Added this new api to allow the serialisation of css declarations. This is not well tested yet, but it works. Dodji.
-rw-r--r--ChangeLog6
-rw-r--r--src/parser/cr-declaration.c72
-rw-r--r--src/parser/cr-declaration.h4
-rw-r--r--tests/test4-main.c13
4 files changed, 92 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 78785cf..e95ac88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
2003-06-09 Dodji <dodji@seketeli.org>
+ * tests/test4-main.c: updated this test to test the
+ new cr_declaration_to_string () api.
+
+ * src/parser/cr-declaration.[ch] (cr_declaration_to_string ()):
+ Added this new api to allow the serialisation of css declarations.
+ This is not well tested yet, but it works.
* src/parser/cr-parser.c (cr_parser_parse_declaration):
fixed a bug that prevented this parsing function to be called outside
diff --git a/src/parser/cr-declaration.c b/src/parser/cr-declaration.c
index 2a1a6b9..a3e9683 100644
--- a/src/parser/cr-declaration.c
+++ b/src/parser/cr-declaration.c
@@ -34,7 +34,6 @@
*The definition of the #CRDeclaration class.
*/
-
/**
*Dumps (serializes) one css declaration to a file.
*@param a_this the current instance of #CRDeclaration.
@@ -324,6 +323,77 @@ cr_declaration_dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent,
}
}
+/**
+ *Serializes the declaration into a string
+ *@param a_this the current instance of #CRDeclaration.
+ *@param a_indent the number of indentation white char
+ *to put before the actual serialisation.
+ */
+guchar *
+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->str)
+ {
+ str = g_strndup (a_this->property->str,
+ a_this->property->len) ;
+ if (str)
+ {
+ cr_utils_dump_n_chars2 (' ', stringue,
+ a_indent) ;
+ g_string_append_printf (stringue, "%s",
+ 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 (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 ;
+}
/**
*Increases the ref count of the current instance of #CRDeclaration.
diff --git a/src/parser/cr-declaration.h b/src/parser/cr-declaration.h
index 748b313..4be7761 100644
--- a/src/parser/cr-declaration.h
+++ b/src/parser/cr-declaration.h
@@ -92,6 +92,10 @@ void
cr_declaration_dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent,
gboolean a_one_per_line) ;
+guchar *
+cr_declaration_to_string (CRDeclaration *a_this,
+ gulong a_indent) ;
+
void
cr_declaration_ref (CRDeclaration *a_this) ;
diff --git a/tests/test4-main.c b/tests/test4-main.c
index 6ece7d2..83ff06f 100644
--- a/tests/test4-main.c
+++ b/tests/test4-main.c
@@ -120,16 +120,25 @@ test_cr_parser_parse (guchar * a_file_uri)
static enum CRStatus
test_cr_declaration_parse (void)
{
+ guchar * tmp_str = NULL ;
CRDeclaration * decl = NULL ;
decl = cr_declaration_parse (NULL, gv_decl,
CR_UTF_8) ;
+ tmp_str = cr_declaration_to_string (decl, 2) ;
if (decl)
{
cr_declaration_destroy (decl) ;
return CR_OK ;
}
+
+ if (tmp_str)
+ {
+ g_free (tmp_str) ;
+ tmp_str = NULL ;
+ }
+
return CR_ERROR ;
}
@@ -141,7 +150,7 @@ main (int argc, char ** argv)
{
struct Options options ;
enum CRStatus status = CR_OK ;
-
+
status = test_cr_declaration_parse () ;
if (status != CR_OK)
@@ -149,7 +158,7 @@ main (int argc, char ** argv)
g_print ("\nKO\n") ;
return 0 ;
}
-
+
cr_test_utils_parse_cmd_line (argc, argv, &options) ;
if (options.display_help == TRUE)