Mercurial > audlegacy
diff src/audacious/tuple_formatter.c @ 3290:4e7cc6d9b525 trunk
add (empty)? function to formatter
| author | William Pitcock <nenolod@atheme-project.org> |
|---|---|
| date | Thu, 09 Aug 2007 09:22:08 -0500 |
| parents | 8576de468e23 |
| children | a97fb19a0148 |
line wrap: on
line diff
--- a/src/audacious/tuple_formatter.c Thu Aug 09 09:05:02 2007 -0500 +++ b/src/audacious/tuple_formatter.c Thu Aug 09 09:22:08 2007 -0500 @@ -43,6 +43,7 @@ * tuple as integer value of "value" * - ${==field,field:expr}: evaluates expr if both fields are the same * - ${!=field,field:expr}: evaluates expr if both fields are not the same + * - ${(empty)?field:expr}: evaluates expr if field is empty or does not exist * * everything else is treated as raw text. * additionally, plugins can add additional instructions! @@ -264,6 +265,33 @@ return tuple_formatter_expression_match(tuple, expression) ^ 1; } +/* builtin-keyword: ${empty?}. returns TRUE if <arg> is empty. */ +static gboolean +tuple_formatter_expression_empty(Tuple *tuple, const gchar *expression) +{ + gboolean ret = TRUE; + const gchar *iter; + TupleValueType type = tuple_get_value_type(tuple, expression); + + if (type == TUPLE_UNKNOWN) + return TRUE; + + if (type == TUPLE_INT && tuple_get_int(tuple, expression) != 0) + return FALSE; + + iter = tuple_get_string(tuple, expression); + + while (ret && *iter != '\0') + { + if (*iter == ' ') + iter++; + else + ret = FALSE; + } + + return ret; +} + /* processes a string containing instructions. does initialization phases if not already done */ gchar * @@ -276,6 +304,7 @@ tuple_formatter_register_expression("?", tuple_formatter_expression_exists); tuple_formatter_register_expression("==", tuple_formatter_expression_match); tuple_formatter_register_expression("!=", tuple_formatter_expression_nonmatch); + tuple_formatter_register_expression("(empty)?", tuple_formatter_expression_empty); initialized = TRUE; }
