Mercurial > audlegacy
changeset 3314:328221f7a580 trunk
fix parser
author | William Pitcock <nenolod@atheme-project.org> |
---|---|
date | Fri, 10 Aug 2007 12:09:58 -0500 |
parents | 257c0d0c5806 |
children | 848999871ae8 |
files | src/audacious/tuple_formatter.c |
diffstat | 1 files changed, 33 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/audacious/tuple_formatter.c Fri Aug 10 10:51:39 2007 -0500 +++ b/src/audacious/tuple_formatter.c Fri Aug 10 12:09:58 2007 -0500 @@ -64,6 +64,7 @@ TupleFormatterContext *ctx; const gchar *iter; gchar *out; + gint level = 0; g_return_val_if_fail(tuple != NULL, NULL); g_return_val_if_fail(string != NULL, NULL); @@ -75,20 +76,24 @@ for (iter = string; *iter != '\0'; iter++) { /* if it's raw text, just copy the byte */ - if (*iter != '$' && *iter != '%') + if (*iter != '$' && *iter != '%' && (*iter != '}' || (*iter == '}' && level > 0))) + { + level--; g_string_append_c(ctx->str, *iter); + } else if (g_str_has_prefix(iter, "${") == TRUE) { GString *expression = g_string_new(""); GString *argument = g_string_new(""); GString *sel = expression; gchar *result; - gint level = 0; + gboolean rewind = FALSE; for (iter += 2; *iter != '\0'; iter++) { if (*iter == ':') { + level++; sel = argument; continue; } @@ -101,14 +106,18 @@ level++; } } - else if (*iter == '}' && (sel == argument && --level > 0)) - g_string_append_c(sel, *iter); - else if (*iter == '}' && ((sel != argument) || (sel == argument && level <= 0))) + else if (*iter == '}' && (sel == argument)) { - if (sel == argument) + level--; + if (level + 1 > 0) + { iter++; + rewind = *(iter - 1) == '}' && *iter != '}'; + break; + } + } + else if (*iter == '}' && ((sel != argument))) break; - } else g_string_append_c(sel, *iter); } @@ -132,6 +141,9 @@ if (*iter == '\0') break; + + if (rewind) + iter--; } else if (g_str_has_prefix(iter, "%{") == TRUE) { @@ -139,12 +151,13 @@ GString *argument = g_string_new(""); GString *sel = expression; gchar *result; - gint level = 0; + gboolean rewind = FALSE; for (iter += 2; *iter != '\0'; iter++) { if (*iter == ':') { + level++; sel = argument; continue; } @@ -157,14 +170,18 @@ level++; } } - else if (*iter == '}' && (sel == argument && --level > 0)) - g_string_append_c(sel, *iter); - else if (*iter == '}' && ((sel != argument) || (sel == argument && level <= 0))) + else if (*iter == '}' && (sel == argument)) { - if (sel == argument) + level--; + if (level + 1 > 0) + { iter++; + rewind = *(iter - 1) == '}' && *iter != '}'; + break; + } + } + else if (*iter == '}' && ((sel != argument))) break; - } else g_string_append_c(sel, *iter); } @@ -188,6 +205,9 @@ if (*iter == '\0') break; + + if (rewind) + iter--; } }