gplate/gplate

Lot's of work here...
no_gscanner
2008-01-20, grim
a88a87a4f5a7
Parents f8eb87fbfabb
Children 4b2c915d4a82
Lot's of work here...

We have basic functionality back, although one of the tests that should be passing right now is failing.
The include test is still failing as well, but I haven't even attempted at getting code tags working yet.
--- a/gplate/gplate-template.c Sun Jan 20 11:33:03 2008 -0600
+++ b/gplate/gplate-template.c Sun Jan 20 11:34:38 2008 -0600
@@ -194,13 +194,18 @@
static void
gplate_template_update_pattern_helper(gpointer k, gpointer v, gpointer d) {
+ GPlateTemplateTagInfo *info = (GPlateTemplateTagInfo *)v;
GString *str = (GString *)d;
- gchar *pattern = (gchar *)v;
+ const gchar *sep = "";
+
+ /* don't add fall through tags to the regex */
+ if(!info->prefix || !info->suffix)
+ return;
if(str->len > 1)
- g_string_append_printf(str, "|%s", pattern);
- else
- g_string_append_printf(str, "%s", pattern);
+ sep = "|";
+
+ g_string_append_printf(str, "%s%s.*?%s", sep, info->prefix, info->suffix);
}
static void
@@ -229,8 +234,8 @@
GPlateTemplateTagInfo *info = (GPlateTemplateTagInfo *)v;
gchar *pattern = NULL;
- /* if our tag info doesn't have a prefix and a suffix, we drop out. */
- if(!info->prefix && !info->suffix)
+ /* if our tag info doesn't have a prefix or a suffix, we drop out. */
+ if(!info->prefix || !info->suffix)
return;
/* create our pattern string */
@@ -329,10 +334,13 @@
}
contents = g_match_info_fetch(match, 1);
+ g_strstrip(contents);
+
g_match_info_free(match);
tag = g_object_new(type,
- "contents", contents);
+ "contents", contents,
+ NULL);
g_free(contents);
}
@@ -517,7 +525,9 @@
gplate_template_render(GPlateTemplate *tplate, const gchar *tplate_string,
GError **error)
{
- GList *tokens = NULL;
+ GList *tokens = NULL, *l = NULL;
+ GString *str = NULL;
+ gchar *ret = NULL;
g_return_val_if_fail(GPLATE_IS_TEMPLATE(tplate), NULL);
g_return_val_if_fail(tplate_string, NULL);
@@ -526,7 +536,24 @@
if(!tokens)
return NULL;
- return NULL;
+ /* for whatever reason, using g_string_new_len here doesn't work */
+ str = g_string_new("");
+
+ for(l = tokens; l; l = l->next) {
+ GPlateTag *tag = GPLATE_TAG(l->data);
+ gchar *contents = gplate_tag_render(tag, GPLATE_COLLECTION(tplate));
+
+ if(contents)
+ g_string_append_printf(str, "%s", contents);
+
+ g_free(contents);
+ }
+
+ ret = str->str;
+
+ g_string_free(str, FALSE);
+
+ return ret;
}
gchar *