--- a/gplate/gplate-library.h Sun Feb 10 01:10:06 2008 -0600
+++ b/gplate/gplate-library.h Sun Feb 10 02:11:03 2008 -0600
@@ -42,6 +42,7 @@
gboolean gplate_library_lookup_function(const gchar *name, GType *function, GType *tag, GError **error);
GType gplate_library_lookup_function_for_tag(const gchar *name, GType tag, GError **error);
+gboolean gplate_library_lookup_tag(GType tag, gchar **prefix, gchar **suffix, GError **error); void gplate_library_tags_foreach(GPlateLibraryTagsForeachFunc func, gpointer data);
--- a/gplate/gplate-template.c Sun Feb 10 01:10:06 2008 -0600
+++ b/gplate/gplate-template.c Sun Feb 10 02:11:03 2008 -0600
@@ -22,12 +22,9 @@
#include <gplate/gplate-template.h>
-#include <gplate/gplate-code-tag.h>
-#include <gplate/gplate-comment-tag.h>
#include <gplate/gplate-dictionary-variable.h>
#include <gplate/gplate-errors.h>
-#include <gplate/gplate-text-tag.h>
-#include <gplate/gplate-variable-tag.h>
+#include <gplate/gplate-library.h> @@ -43,8 +40,6 @@
*****************************************************************************/
@@ -54,50 +49,12 @@
-} GPlateTemplateTagInfo;
/******************************************************************************
*****************************************************************************/
static GObjectClass *parent_class = NULL;
/******************************************************************************
- *****************************************************************************/
-static GPlateTemplateTagInfo *
-gplate_template_tag_info_new(GType type) {
- GPlateTemplateTagInfo *info = NULL;
- GPlateTagClass *tag_class = NULL;
- const gchar *prefix, *suffix;
- tag_class = g_type_class_ref(type);
- prefix = gplate_tag_class_get_prefix(tag_class);
- suffix = gplate_tag_class_get_suffix(tag_class);
- info = g_new(GPlateTemplateTagInfo, 1);
- info->prefix = (prefix) ? g_strdup(prefix) : NULL;
- info->suffix = (suffix) ? g_strdup(suffix) : NULL;
- g_type_class_unref(tag_class);
-gplate_template_tag_info_free(GPlateTemplateTagInfo *info) {
-/******************************************************************************
*****************************************************************************/
@@ -129,92 +86,21 @@
/******************************************************************************
*****************************************************************************/
-gplate_template_real_add_tag(GPlateTemplate *tplate, GType tag, GError **e) {
- GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate);
- GPlateTemplateTagInfo *info = NULL;
- if(g_hash_table_lookup(priv->tags, GSIZE_TO_POINTER(tag))) {
- g_error_new(GPLATE_DOMAIN, GPLATE_ERROR_TAG_EXISTS,
- "Tag '%s' has already been added.\n",
- info = gplate_template_tag_info_new(tag);
- if(info->prefix && info->suffix) {
- g_hash_table_insert(priv->tags, GSIZE_TO_POINTER(tag), info);
- } else if(!info->prefix && !info->suffix) {
- /* this should be a fall through tag */
- if(priv->fall_through != G_TYPE_INVALID) {
- *e = g_error_new(GPLATE_DOMAIN,
- GPLATE_ERROR_TAG_FALL_THROUGH_EXISTS,
- "A fall through tag named '%s' has alread "
- g_type_name(priv->fall_through));
- gplate_template_tag_info_free(info);
- priv->fall_through = tag;
- g_hash_table_insert(priv->tags, GSIZE_TO_POINTER(tag), info);
- } else if(!info->prefix && info->suffix) {
- /* misconfigured tag, no prefix, but has suffix */
- *e = g_error_new(GPLATE_DOMAIN,
- GPLATE_ERROR_TAG_NO_PREFIX_HAVE_SUFFIX,
- "Tag '%s' has no prefix, but has a suffix.\n",
- gplate_template_tag_info_free(info);
- } else if(info->prefix && !info->suffix) {
- /* misconfigured tag, has prefix, but no suffix */
- *e = g_error_new(GPLATE_DOMAIN,
- GPLATE_ERROR_TAG_HAVE_PREFIX_NO_SUFFIX,
- "Tag '%s' has a prefix, but no suffix.\n",
- gplate_template_tag_info_free(info);
- /* clean up pattern, if it exists, since it needs to be rebuilt */
-gplate_template_update_pattern_helper(gpointer k, gpointer v, gpointer d) {
- GPlateTemplateTagInfo *info = (GPlateTemplateTagInfo *)v;
+gplate_template_update_pattern_helper(GType tag, const gchar *prefix, + const gchar *suffix, gpointer d) GString *str = (GString *)d;
/* don't add fall through tags to the regex */
- if(!info->prefix || !info->suffix)
- g_string_append_printf(str, "%s%s.*?%s", sep, info->prefix, info->suffix);
+ g_string_append_printf(str, "%s%s.*?%s", sep, prefix, suffix); @@ -222,8 +108,7 @@
GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate);
GString *str = g_string_new("(");
- g_hash_table_foreach(priv->tags, gplate_template_update_pattern_helper,
+ gplate_library_tags_foreach(gplate_template_update_pattern_helper, str); g_string_append_printf(str, "%s", ")");
@@ -238,17 +123,18 @@
} GPlateTemplateFindTagData;
-gplate_template_find_tag_helper(gpointer k, gpointer v, gpointer d) {
+gplate_template_find_tag_helper(GType tag, const gchar *prefix, + const gchar *suffix, gpointer d) GPlateTemplateFindTagData *data = (GPlateTemplateFindTagData *)d;
- GPlateTemplateTagInfo *info = (GPlateTemplateTagInfo *)v;
/* if our tag info doesn't have a prefix or a suffix, we drop out. */
- if(!info->prefix || !info->suffix)
/* create our pattern string */
- pattern = g_strdup_printf("%s.*?%s", info->prefix, info->suffix);
+ pattern = g_strdup_printf("%s.*?%s", prefix, suffix); @@ -257,7 +143,7 @@
* ie: {{\nfoo\n}} would be treated as a fall through if not for it.
if(g_regex_match_simple(pattern, data->contents, G_REGEX_DOTALL, 0))
- data->type = GPOINTER_TO_SIZE(k);
@@ -271,7 +157,7 @@
- g_hash_table_foreach(priv->tags, gplate_template_find_tag_helper, &d);
+ gplate_library_tags_foreach(gplate_template_find_tag_helper, &d); return (d.type == G_TYPE_INVALID) ? priv->fall_through : d.type;
@@ -297,19 +183,18 @@
for(i = 0; matches[i]; i++) {
- GPlateTemplateTagInfo *info = NULL;
GType type = G_TYPE_INVALID;
+ gchar *prefix = NULL, *suffix = NULL; if(g_utf8_strlen(matches[i], -1) <= 0)
type = gplate_template_find_tag(tplate, matches[i]);
- info = g_hash_table_lookup(priv->tags, GSIZE_TO_POINTER(type));
+ if(!gplate_library_lookup_tag(type, &prefix, &suffix, error)) - if(!info->prefix && !info->suffix) {
+ if(!prefix && !suffix) { /* it's a fall through tag */
@@ -320,7 +205,7 @@
GMatchInfo *match = NULL;
gchar *pattern = NULL, *contents = NULL;
- pattern = g_strdup_printf("%s(.*?)%s", info->prefix, info->suffix);
+ pattern = g_strdup_printf("%s(.*?)%s", prefix, suffix); regex2 = g_regex_new(pattern,
G_REGEX_OPTIMIZE | G_REGEX_DOTALL,
@@ -382,8 +267,6 @@
gplate_template_finalize(GObject *obj) {
GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(obj);
- g_hash_table_destroy(priv->tags);
g_object_unref(priv->vars);
@@ -401,7 +284,6 @@
obj_class->finalize = gplate_template_finalize;
- klass->add_tag = gplate_template_real_add_tag;
klass->tokenize = gplate_template_real_tokenize;
@@ -409,10 +291,6 @@
gplate_template_init(GTypeInstance *self, gpointer klass) {
GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(self);
- g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
- (GDestroyNotify)gplate_template_tag_info_free);
priv->fall_through = G_TYPE_INVALID;
@@ -468,62 +346,10 @@
gplate_template_new(void) {
GPlateTemplate *tplate = g_object_new(GPLATE_TYPE_TEMPLATE, NULL);
- gplate_template_add_tag(tplate, GPLATE_TYPE_CODE_TAG, NULL);
- gplate_template_add_tag(tplate, GPLATE_TYPE_COMMENT_TAG, NULL);
- gplate_template_add_tag(tplate, GPLATE_TYPE_TEXT_TAG, NULL);
- gplate_template_add_tag(tplate, GPLATE_TYPE_VARIABLE_TAG, NULL);
- * gplate_template_add_tag:
- * @tplate: The #GPlateTemplate.
- * @tag: The GType of the tag.
- * @error: Return address for any errors.
- * Adds #tag to the template.
- * Return Value: TRUE on success, other FALSE.
-gplate_template_add_tag(GPlateTemplate *tplate, GType tag, GError **error) {
- GPlateTemplateClass *klass = NULL;
- g_return_val_if_fail(GPLATE_IS_TEMPLATE(tplate), FALSE);
- if(!g_type_is_a(tag, GPLATE_TYPE_TAG)) {
- g_error_new(GPLATE_DOMAIN, GPLATE_ERROR_TYPE_IS_NOT_DESCENDANT,
- "type '%s' is not a child of '%s'.\n",
- g_type_name(GPLATE_TYPE_TAG));
- if(G_TYPE_IS_ABSTRACT(tag)) {
- g_error_new(GPLATE_DOMAIN, GPLATE_ERROR_TYPE_IS_ABSTRACT,
- "type '%s' is abstract.\n",
- klass = GPLATE_TEMPLATE_GET_CLASS(tplate);
- if(klass && klass->add_tag)
- return klass->add_tag(tplate, tag, error);
* gplate_template_tokenize:
* @tplate: The #GPlateTemplate.
* @tplate_string: The string to be translated.
--- a/gplate/gplate-template.h Sun Feb 10 01:10:06 2008 -0600
+++ b/gplate/gplate-template.h Sun Feb 10 02:11:03 2008 -0600
@@ -46,8 +46,6 @@
struct _GPlateTemplateClass {
- gboolean (*add_tag)(GPlateTemplate *tplate, GType tag, GError **error);
GList *(*tokenize)(GPlateTemplate *tplate, const gchar *tplate_string, GError **error);
GPlateTag *(*first_tag)(GPlateTemplate *tplate);
@@ -69,8 +67,6 @@
GPlateTemplate *gplate_template_new(void);
-gboolean gplate_template_add_tag(GPlateTemplate *tplate, GType tag, GError **error);
GList *gplate_template_tokenize(GPlateTemplate *tplate, const gchar *tplate_string, GError **error);
gchar *gplate_template_render(GPlateTemplate *tplate, const gchar *tplate_string, GError **error);