grim/gplate

Parents ae2f9362c118
Children dc862ebf1139
Creating a branch for moving render until into GPlateTemplate rather than having everyone handle it themselves
--- a/gplate/gplate-template.c Wed Feb 27 23:19:32 2008 -0600
+++ b/gplate/gplate-template.c Sun Mar 02 00:57:58 2008 -0600
@@ -49,6 +49,11 @@
GList *current_token;
} GPlateTemplatePrivate;
+typedef struct {
+ GType type;
+ gchar *contents;
+} GPlateTemplateTagData;
+
/******************************************************************************
* Globals
*****************************************************************************/
@@ -130,16 +135,11 @@
return ret;
}
-typedef struct {
- const gchar *contents;
- GType type;
-} GPlateTemplateFindTagData;
-
static void
gplate_template_find_tag_helper(GType tag, const gchar *prefix,
const gchar *suffix, gpointer d)
{
- GPlateTemplateFindTagData *data = (GPlateTemplateFindTagData *)d;
+ GPlateTemplateTagData *data = (GPlateTemplateTagData *)d;
gchar *pattern = NULL;
/* if our tag info doesn't have a prefix or a suffix, we drop out. */
@@ -163,8 +163,8 @@
}
static GType
-gplate_template_find_tag(GPlateTemplate *tplate, const gchar *contents) {
- GPlateTemplateFindTagData d;
+gplate_template_find_tag(GPlateTemplate *tplate, gchar *contents) {
+ GPlateTemplateTagData d;
d.contents = contents;
d.type = G_TYPE_INVALID;
@@ -640,6 +640,80 @@
return ret;
}
+gchar *
+gplate_template_render_until(GPlateTemplate *tplate, ...) {
+ GPlateTag *tag = NULL;
+ GList *l = NULL;
+ GString *str = NULL;
+ GQueue *queue = NULL;
+ gchar *ret = NULL;
+ gchar *contents = NULL;
+ va_list args;
+
+ g_return_val_if_fail(GPLATE_IS_TEMPLATE(tplate), NULL);
+
+ str = g_string_new("");
+
+ queue = g_queue_new();
+
+ /* store all of the content/tag pairs */
+ va_start(args, tplate);
+ while((contents = va_arg(args, gchar *)) != NULL) {
+ GPlateTemplateTagData *td = NULL;
+
+ td = g_new(GPlateTemplateTagData, 1);
+
+ td->contents = contents;
+ td->type = va_arg(args, GType);
+
+ g_queue_push_tail(queue, td);
+ }
+ va_end(args);
+
+ /* now iterate the tags */
+ while((tag = gplate_template_next_tag(tplate))) {
+ GPlateTemplateTagData ctd;
+ gboolean stop = FALSE;
+
+ ctd.contents = gplate_tag_get_contents(tag);
+ ctd.type = G_OBJECT_TYPE(tag);
+
+ /* run through our list of TagData's to stop on */
+ for(l = queue->head; l; l = l->next) {
+ GPlateTemplateTagData *td = (GPlateTemplateTagData *)l->data;
+
+ if(ctd.type == td->type &&
+ g_utf8_collate(ctd.contents, td->contents) == 0)
+ {
+ stop = TRUE;
+ }
+ }
+
+ g_free(ctd.contents);
+
+ if(stop)
+ break;
+
+ g_string_append_printf(str, "%s",
+ gplate_template_render_tag(tplate, tag));
+ }
+
+ /* now clean everything up... */
+ for(l = queue->head; l; l = l->next) {
+ GPlateTemplateTagData *td = (GPlateTemplateTagData *)l->data;
+
+ g_free(td->contents);
+ g_free(td);
+ }
+
+ g_queue_free(queue);
+
+ ret = str->str;
+ g_string_free(str, FALSE);
+
+ return ret;
+}
+
/**
* gplate_template_first_tag:
* @tplate: The #GPlateTemplate.
--- a/gplate/gplate-template.h Wed Feb 27 23:19:32 2008 -0600
+++ b/gplate/gplate-template.h Sun Mar 02 00:57:58 2008 -0600
@@ -76,6 +76,8 @@
gchar *gplate_template_render(GPlateTemplate *tplate, const gchar *tplate_string, GError **error);
gchar *gplate_template_render_file(GPlateTemplate *tplate, const gchar *filename, GError **error);
+gchar *gplate_template_render_until(GPlateTemplate *tplate, ...);
+
GPlateTag *gplate_template_first_tag(GPlateTemplate *tplate);
GPlateTag *gplate_template_last_tag(GPlateTemplate *tplate);
GPlateTag *gplate_template_current_tag(GPlateTemplate *tplate);