diff options
author | jerous <jerous@gmail.com> | 2008-09-28 00:52:29 +0200 |
---|---|---|
committer | jerous <jerous@gmail.com> | 2008-09-28 00:52:29 +0200 |
commit | 5d4a94d2929a5f0401320c9368d3d2ffd582964f (patch) | |
tree | 3e4c16b98eac559629cd73c49f3590b6a4bc62be | |
parent | 95bcfd646d9cebc4e85120e836fe6537b8b648be (diff) |
fix with nested brackets in a format
-rw-r--r-- | format.py | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -70,7 +70,7 @@ def match_bracket(string, start): balance=1 start+=1 while balance>0: - if start>len(string): + if start<=0: raise Exception("No matching bracket found") l=string.find("(", start) r=string.find(")", start) @@ -78,10 +78,11 @@ def match_bracket(string, start): if l<0: if r>0: balance-=1 else: return -1 + start=r+1 else: if l<r: balance+=1 - elif r<l: balance-=1 - start=min(l,r)+1 + elif l>r: balance-=1 + start=min(l,r)+1 if balance==0: return r+1 @@ -100,6 +101,7 @@ def params(song, overwrite={}, ensure={"title":"", "artist":""\ params[param]=overwrite[param] return params +#f=compile("$if($date, ($date) )") #f=compile("a$if($title,$title)b$if($artist,$artist)c") #print f({'state':'playing', 'title':'martha', 'artist':'waits'}) #f=compile("$artist $if($title, titeltje:$artist, $artist $title!) $album") |