changeset 3518:3a2ee00bc962 trunk

${?field:...} -> check if there's data in it, making it the opposite of the (empty)? expression.
author William Pitcock <nenolod@atheme.org>
date Wed, 12 Sep 2007 00:22:52 -0500
parents b747ad540903
children ae0b80004a41
files src/audacious/tuple_formatter.c
diffstat 1 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/tuple_formatter.c	Tue Sep 11 20:34:55 2007 -0500
+++ b/src/audacious/tuple_formatter.c	Wed Sep 12 00:22:52 2007 -0500
@@ -379,11 +379,32 @@
     tuple_formatter_func_list = g_list_append(tuple_formatter_func_list, expr);
 }
 
-/* builtin-keyword: ${?arg}, returns TRUE if <arg> exists. */
+/* builtin-keyword: ${?arg}, returns TRUE if <arg> exists and is not empty. */
 static gboolean
 tuple_formatter_expression_exists(Tuple *tuple, const gchar *expression)
 {
-    return (tuple_get_value_type(tuple, -1, expression) != TUPLE_UNKNOWN) ? TRUE : FALSE;
+    gboolean ret = FALSE;
+    TupleValueType type = tuple_get_value_type(tuple, -1, expression);
+    const gchar *iter;
+
+    if (type == TUPLE_UNKNOWN)
+        return FALSE;
+
+    /* TBD: check if zero? --nenolod */
+    if (type == TUPLE_INT)
+        return TRUE;
+
+    iter = tuple_get_string(tuple, -1, expression);
+
+    while (ret && *iter != '\0')
+    {
+        if (*iter == ' ')
+            iter++;
+        else
+            ret = TRUE;
+    }
+
+    return ret;
 }
 
 /* builtin-keyword: ${==arg1,arg2}, returns TRUE if <arg1> and <arg2> match.