--- a/gplate/gplate-template.c Sun Feb 10 22:14:32 2008 -0600
+++ b/gplate/gplate-template.c Mon Feb 11 03:44:52 2008 -0600
@@ -40,11 +40,10 @@
*****************************************************************************/
/******************************************************************************
@@ -101,18 +100,20 @@
g_string_append_printf(str, "%s%s.*?%s", sep, prefix, suffix);
gplate_template_update_pattern(GPlateTemplate *tplate) {
- GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate);
GString *str = g_string_new("(");
gplate_library_tags_foreach(gplate_template_update_pattern_helper, str);
g_string_append_printf(str, "%s", ")");
- priv->pattern = str->str;
g_string_free(str, FALSE);
@@ -166,18 +167,22 @@
gplate_template_real_tokenize(GPlateTemplate *tplate, const gchar *tplate_string,
- GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate);
- gplate_template_update_pattern(tplate);
+ pattern = gplate_template_update_pattern(tplate); - regex1 = g_regex_new(priv->pattern, G_REGEX_OPTIMIZE, 0, error);
+ regex1 = g_regex_new(pattern, G_REGEX_OPTIMIZE, 0, error); matches = g_regex_split(regex1, tplate_string, 0);
@@ -260,17 +265,109 @@
+gplate_template_real_first_tag(GPlateTemplate *tplate) { + GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate); + priv->current_token = priv->tokens; + if(priv->current_token && GPLATE_IS_TAG(priv->current_token->data)) + tag = GPLATE_TAG(priv->current_token->data); +gplate_template_real_last_tag(GPlateTemplate *tplate) { + GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate); + priv->current_token = g_list_last(priv->tokens); + if(priv->current_token && GPLATE_IS_TAG(priv->current_token->data)) + tag = GPLATE_TAG(priv->current_token->data); +gplate_template_real_current_tag(GPlateTemplate *tplate) { + GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate); + if(priv->current_token && GPLATE_IS_TAG(priv->current_token->data)) + tag = GPLATE_TAG(priv->current_token->data); +gplate_template_real_next_tag(GPlateTemplate *tplate) { + GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate); + priv->current_token = g_list_next(priv->current_token); + if(priv->current_token && GPLATE_IS_TAG(priv->current_token->data)) + tag = GPLATE_TAG(priv->current_token->data); +gplate_template_real_previous_tag(GPlateTemplate *tplate) { + GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate); + priv->current_token = g_list_previous(priv->current_token); + if(priv->current_token && GPLATE_IS_TAG(priv->current_token->data)) + tag = GPLATE_TAG(priv->current_token->data); +gplate_template_real_nth_tag(GPlateTemplate *tplate, guint nth) { + GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate); + priv->current_token = g_list_nth(priv->current_token, nth); + if(priv->current_token && GPLATE_IS_TAG(priv->current_token->data)) + tag = GPLATE_TAG(priv->current_token->data); +gplate_template_real_nth_previous_tag(GPlateTemplate *tplate, guint nth) { + GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate); + priv->current_token = g_list_nth_prev(priv->current_token, nth); + if(priv->current_token && GPLATE_IS_TAG(priv->current_token->data)) + tag = GPLATE_TAG(priv->current_token->data); /******************************************************************************
*****************************************************************************/
gplate_template_finalize(GObject *obj) {
GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(obj);
g_object_unref(priv->vars);
+ for(l = priv->tokens; l; l = l->next) + g_object_unref(G_OBJECT(l->data)); + g_list_free(priv->tokens); G_OBJECT_CLASS(parent_class)->finalize(obj);
@@ -285,14 +382,20 @@
obj_class->finalize = gplate_template_finalize;
klass->tokenize = gplate_template_real_tokenize;
+ klass->first_tag = gplate_template_real_first_tag; + klass->last_tag = gplate_template_real_last_tag; + klass->current_tag = gplate_template_real_current_tag; + klass->next_tag = gplate_template_real_next_tag; + klass->previous_tag = gplate_template_real_previous_tag; + klass->nth_tag = gplate_template_real_nth_tag; + klass->nth_previous_tag = gplate_template_real_nth_previous_tag; gplate_template_init(GTypeInstance *self, gpointer klass) {
GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(self);
priv->vars = gplate_dictionary_variable_new("dict");
@@ -491,6 +594,20 @@
+gplate_template_current_tag(GPlateTemplate *tplate) { + GPlateTemplateClass *klass = NULL; + g_return_val_if_fail(GPLATE_IS_TEMPLATE(tplate), NULL); + klass = GPLATE_TEMPLATE_GET_CLASS(tplate); + if(klass && klass->current_tag) + return klass->current_tag(tplate); gplate_template_next_tag(GPlateTemplate *tplate) {
GPlateTemplateClass *klass = NULL;
@@ -519,7 +636,7 @@
-gplate_template_nth_tag(GPlateTemplate *tplate) {
+gplate_template_nth_tag(GPlateTemplate *tplate, guint nth) { GPlateTemplateClass *klass = NULL;
g_return_val_if_fail(GPLATE_IS_TEMPLATE(tplate), NULL);
@@ -527,13 +644,13 @@
klass = GPLATE_TEMPLATE_GET_CLASS(tplate);
if(klass && klass->nth_tag)
- return klass->nth_tag(tplate);
+ return klass->nth_tag(tplate, nth); -gplate_template_nth_previous_tag(GPlateTemplate *tplate) {
+gplate_template_nth_previous_tag(GPlateTemplate *tplate, guint nth) { GPlateTemplateClass *klass = NULL;
g_return_val_if_fail(GPLATE_IS_TEMPLATE(tplate), NULL);
@@ -541,7 +658,7 @@
klass = GPLATE_TEMPLATE_GET_CLASS(tplate);
if(klass && klass->nth_previous_tag)
- return klass->nth_previous_tag(tplate);
+ return klass->nth_previous_tag(tplate, nth); --- a/gplate/gplate-template.h Sun Feb 10 22:14:32 2008 -0600
+++ b/gplate/gplate-template.h Mon Feb 11 03:44:52 2008 -0600
@@ -50,10 +50,11 @@
GPlateTag *(*first_tag)(GPlateTemplate *tplate);
GPlateTag *(*last_tag)(GPlateTemplate *tplate);
+ GPlateTag *(*current_tag)(GPlateTemplate *tplate); GPlateTag *(*next_tag)(GPlateTemplate *tplate);
GPlateTag *(*previous_tag)(GPlateTemplate *tplate);
- GPlateTag *(*nth_tag)(GPlateTemplate *tplate);
- GPlateTag *(*nth_previous_tag)(GPlateTemplate *tplate);
+ GPlateTag *(*nth_tag)(GPlateTemplate *tplate, guint nth); + GPlateTag *(*nth_previous_tag)(GPlateTemplate *tplate, guint nth); void (*_gplate_reserved1)(void);
void (*_gplate_reserved2)(void);
@@ -74,10 +75,11 @@
GPlateTag *gplate_template_first_tag(GPlateTemplate *tplate);
GPlateTag *gplate_template_last_tag(GPlateTemplate *tplate);
+GPlateTag *gplate_template_current_tag(GPlateTemplate *tplate); GPlateTag *gplate_template_next_tag(GPlateTemplate *tplate);
GPlateTag *gplate_template_previous_tag(GPlateTemplate *tplate);
-GPlateTag *gplate_template_nth_tag(GPlateTemplate *tplate);
-GPlateTag *gplate_template_nth_previous_tag(GPlateTemplate *tplate);
+GPlateTag *gplate_template_nth_tag(GPlateTemplate *tplate, guint nth); +GPlateTag *gplate_template_nth_previous_tag(GPlateTemplate *tplate, guint nth);