diff options
author | Dodji Seketeli <dodji@src.gnome.org> | 2003-03-19 22:13:11 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2003-03-19 22:13:11 +0000 |
commit | b370f217eed617133e5ed8bc9ff28b6669fc5e05 (patch) | |
tree | defe3e569b19ecda0deb64841f3549ceb73c1a3f /src/cr-simple-sel.c | |
parent | cc7ec65a2b735e285047c7e0a61212337d7ab24c (diff) | |
download | libcroco-b370f217eed617133e5ed8bc9ff28b6669fc5e05.tar.gz |
added better in memory serialisation to the selector related data structures. Dodji.
Diffstat (limited to 'src/cr-simple-sel.c')
-rw-r--r-- | src/cr-simple-sel.c | 86 |
1 files changed, 66 insertions, 20 deletions
diff --git a/src/cr-simple-sel.c b/src/cr-simple-sel.c index 518fabb..edb19d3 100644 --- a/src/cr-simple-sel.c +++ b/src/cr-simple-sel.c @@ -95,48 +95,47 @@ cr_simple_sel_prepend_simple_sel (CRSimpleSel *a_this, CRSimpleSel *a_sel) return a_sel ; } - -/** - *Dumps the selector to a file. - *TODO: add the support of unicode in the dump. - * - *@param a_this the current instance of #CRSimpleSel. - *@param a_fp the destination file pointer. - *@return CR_OK upon successfull completion, an error code - *otherwise. - */ -enum CRStatus -cr_simple_sel_dump (CRSimpleSel *a_this, FILE *a_fp) +guchar * +cr_simple_sel_to_string (CRSimpleSel *a_this) { + GString * str_buf = NULL ; + guchar *result = NULL ; + CRSimpleSel *cur = NULL ; - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, NULL) ; + str_buf = g_string_new (NULL) ; for (cur = a_this ; cur ; cur = cur->next) { if (cur->name) { guchar * str = g_strndup (cur->name->str, - cur->name->len) ; + cur->name->len) ; if (str) { switch (cur->combinator) { case COMB_WS: - fprintf (a_fp," ") ; + g_string_append_printf + (str_buf, " ") ; break ; + case COMB_PLUS: - fprintf (a_fp,"+") ; + g_string_append_printf + (str_buf, "+") ; break ; + case COMB_GT: - fprintf (a_fp,">") ; + g_string_append_printf + (str_buf, ">") ; break ; + default: break ; } - fprintf (a_fp,str) ; - + g_string_append_printf (str_buf,"%s",str) ; g_free (str) ; str = NULL ; } @@ -144,7 +143,54 @@ cr_simple_sel_dump (CRSimpleSel *a_this, FILE *a_fp) if (cur->add_sel) { - cr_additional_sel_dump (cur->add_sel, a_fp) ; + guchar *tmp_str = NULL ; + + tmp_str = cr_additional_sel_to_string + (cur->add_sel) ; + if (tmp_str) + { + g_string_append_printf + (str_buf, "%s", tmp_str) ; + g_free (tmp_str) ; + tmp_str = NULL ; + } + } + } + + if (str_buf) + { + result = str_buf->str ; + g_string_free (str_buf, FALSE) ; + str_buf = NULL ; + } + + return result ; +} + +/** + *Dumps the selector to a file. + *TODO: add the support of unicode in the dump. + * + *@param a_this the current instance of #CRSimpleSel. + *@param a_fp the destination file pointer. + *@return CR_OK upon successfull completion, an error code + *otherwise. + */ +enum CRStatus +cr_simple_sel_dump (CRSimpleSel *a_this, FILE *a_fp) +{ + guchar *tmp_str = NULL ; + + g_return_val_if_fail (a_fp, CR_BAD_PARAM_ERROR) ; + + if (a_this) + { + tmp_str = cr_simple_sel_to_string (a_this) ; + if (tmp_str) + { + fprintf (a_fp, "%s", tmp_str) ; + g_free (tmp_str) ; + tmp_str = NULL ; } } |