changeset 3335:63d7947d7376 trunk

simplified the tuple formatter a bit
author Giacomo Lozito <james@develia.org>
date Sat, 11 Aug 2007 20:32:13 +0200
parents ea806daf3ef0
children 904c58081f0a
files src/audacious/tuple_formatter.c
diffstat 1 files changed, 14 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/tuple_formatter.c	Sat Aug 11 23:59:24 2007 +0900
+++ b/src/audacious/tuple_formatter.c	Sat Aug 11 20:32:13 2007 +0200
@@ -86,10 +86,13 @@
     for (iter = string; *iter != '\0'; iter++)
     {
         /* if it's raw text, just copy the byte */
-        if (*iter != '$' && *iter != '%' && (*iter != '}' || (*iter == '}' && level > 0)))
+        if (*iter != '$' && *iter != '%' && *iter != '}' )
+        {
+            g_string_append_c(ctx->str, *iter);
+        }
+        else if (*iter == '}' && level > 0)
         {
             level--;
-            g_string_append_c(ctx->str, *iter);
         }
         else if (g_str_has_prefix(iter, "${") == TRUE)
         {
@@ -97,13 +100,12 @@
             GString *argument = g_string_new("");
             GString *sel = expression;
             gchar *result;
-            gboolean rewind = FALSE;
+            level++;
 
             for (iter += 2; *iter != '\0'; iter++)
             {
                 if (*iter == ':')
                 {
-		    level++;
                     if (sel != argument)
                     {
                         sel = argument;
@@ -125,13 +127,10 @@
                 else if (*iter == '}' && (sel == argument))
                 {
                     level--;
-                    if (level + 1 > 0)
-                    {
-                        iter++;
-                        rewind = *(iter - 1) == '}' && *iter != '}';
-                        break;
-                    }
-                    g_string_append_c(sel, *iter);
+                    if (level == 0)
+                      break;
+                    else
+                      g_string_append_c(sel, *iter);
                 }
                 else if (*iter == '}' && ((sel != argument)))
                     break;
@@ -158,9 +157,6 @@
 
             if (*iter == '\0')
                 break;
-
-            if (rewind)
-                iter--;
         }
         else if (g_str_has_prefix(iter, "%{") == TRUE)
         {
@@ -168,13 +164,12 @@
             GString *argument = g_string_new("");
             GString *sel = expression;
             gchar *result;
-            gboolean rewind = FALSE;
+            level++;
 
             for (iter += 2; *iter != '\0'; iter++)
             {
                 if (*iter == ':')
                 {
-		    level++;
                     if (sel != argument)
                     {
                         sel = argument;
@@ -196,12 +191,9 @@
                 else if (*iter == '}' && (sel == argument))
                 {
                     level--;
-                    if (level + 1 > 0)
-                    {
-                        iter++;
-                        rewind = *(iter - 1) == '}' && *iter != '}';
-                        break;
-                    }
+                    if (level == 0)
+                      break;
+                    else
                     g_string_append_c(sel, *iter);
                 }
                 else if (*iter == '}' && ((sel != argument)))
@@ -229,9 +221,6 @@
 
             if (*iter == '\0')
                 break;
-
-            if (rewind)
-                iter--;
         }
     }