grim/gplate

Rewrote GPlatePrintFunction to treat non-quoted strings as variables.
trying_to_get_includes_working
2008-02-19, grim
00fd8a59b7b2
Parents 963f73ea13a5
Children 441ed95410c3
Rewrote GPlatePrintFunction to treat non-quoted strings as variables.
Removed the GetContents override in GPlateVariableTag since GPlatePrintFunction is smart enough now to know the difference between a string and a variable.
--- a/gplate/gplate-print-function.c Tue Feb 19 23:51:18 2008 -0600
+++ b/gplate/gplate-print-function.c Tue Feb 19 23:52:37 2008 -0600
@@ -22,6 +22,9 @@
#include <gplate/gplate-print-function.h>
+#include <gplate/gplate-collection.h>
+#include <gplate/gplate-util.h>
+
/******************************************************************************
* PrintFunction Stuff
*****************************************************************************/
@@ -30,7 +33,26 @@
GPlateTemplate *tplate,
const gchar *contents)
{
- return (contents) ? g_strdup(contents) : g_strdup("");
+ gchar *ret = NULL;
+
+ /* check for a quoted string, if it is quoted, we don't need to do
+ * anything, since it's already stored in ret.
+ */
+ if(!gplate_util_is_quoted_string(contents, &ret)) {
+ GPlateVariable *var = NULL;
+
+ var = gplate_collection_find_variable(GPLATE_COLLECTION(tplate),
+ contents);
+
+ if(GPLATE_IS_VARIABLE(var)) {
+ const gchar *val = gplate_variable_get_value(var);
+
+ if(val)
+ ret = g_strdup(val);
+ }
+ }
+
+ return (ret) ? ret : g_strdup("");
}
/******************************************************************************
--- a/gplate/gplate-variable-tag.c Tue Feb 19 23:51:18 2008 -0600
+++ b/gplate/gplate-variable-tag.c Tue Feb 19 23:52:37 2008 -0600
@@ -43,78 +43,6 @@
return "}}";
}
-static gchar *
-gplate_variable_tag_get_contents(const GPlateTag *tag) {
- GPlateTemplate *tplate = NULL;
- GPlateVariable *variable = NULL;
- GRegex *regex = NULL;
- GMatchInfo *info = NULL;
- gchar *name = NULL, *contents = NULL;
- const gchar *value = NULL;
-
- /* create our regex with available variable characters and ignore
- * everything after the first variable.
- *
- * We shouldn't be seeing newlines here since the contents is
- * stripped before our tag even gets created.
- */
- regex = g_regex_new("([A-Za-z0-9_.]+).*", 0, 0, NULL);
- if(!regex)
- return g_strdup("");
-
- /* grab the contents from the parent */
- contents = GPLATE_TAG_CLASS(parent_class)->get_contents(tag);
-
- /* make sure our regex matches */
- if(!g_regex_match(regex, contents, 0, &info)) {
- g_free(contents);
- g_regex_unref(regex);
-
- return g_strdup("");
- }
-
- /* we don't need the regex anymore */
- g_regex_unref(regex);
-
- /* make sure we have the correct number of matches */
- if(g_match_info_get_match_count(info) < 2) {
- g_free(contents);
- g_match_info_free(info);
-
- return g_strdup("");
- }
-
- /* get and validate the variable name */
- name = g_match_info_fetch(info, 1);
-
- g_free(contents);
-
- if(!name) {
- g_match_info_free(info);
-
- return g_strdup("");
- }
-
- /* find the variable from the name */
- tplate = gplate_tag_get_template(tag);
- variable = gplate_collection_find_variable(GPLATE_COLLECTION(tplate),
- name);
- g_free(name);
-
- /* clean up the match info */
- g_match_info_free(info);
-
- /* validate our variable */
- if(!GPLATE_IS_VARIABLE(variable))
- return g_strdup("");
-
- /* get the value */
- value = gplate_variable_get_value(variable);
-
- /* return the value */
- return (value) ? g_strdup(value) : g_strdup("");
-}
-
/******************************************************************************
* Object Stuff
*****************************************************************************/
@@ -126,8 +54,6 @@
tag_class->get_prefix = gplate_variable_tag_class_get_prefix;
tag_class->get_suffix = gplate_variable_tag_class_get_suffix;
-
- tag_class->get_contents = gplate_variable_tag_get_contents;
}
/******************************************************************************