make parsestring work with strings that do not have quotes.
authorVadim Gelfer <vadim.gelfer@gmail.com>
Mon, 27 Feb 2006 11:18:56 -0800
changeset 1902 1cc5f25653a3
parent 1901 c64bef3d7043
child 1903 e4abeafd6eb1
make parsestring work with strings that do not have quotes.
mercurial/templater.py
--- a/mercurial/templater.py	Mon Feb 27 09:35:43 2006 -0800
+++ b/mercurial/templater.py	Mon Feb 27 11:18:56 2006 -0800
@@ -11,19 +11,21 @@
     'v': '\v',
     }
 
-def parsestring(s):
+def parsestring(s, quoted=True):
     fp = cStringIO.StringIO()
+    if quoted:
+        first = s[0]
+        if len(s) < 2: raise SyntaxError(_('string too short'))
+        if first not in "'\"": raise SyntaxError(_('invalid quote'))
+        if s[-1] != first: raise SyntaxError(_('unmatched quotes'))
+        s = s[1:-1]
     escape = False
-    first = s[0]
-    if len(s) < 2: raise SyntaxError(_('string too short'))
-    if first not in "'\"": raise SyntaxError(_('invalid quote'))
-    if s[-1] != first: raise SyntaxError(_('unmatched quotes'))
-    for c in s[1:-1]:
+    for c in s:
         if escape:
             fp.write(esctable.get(c, c))
             escape = False
         elif c == '\\': escape = True
-        elif c == first: raise SyntaxError(_('string ends early'))
+        elif quoted and c == first: raise SyntaxError(_('string ends early'))
         else: fp.write(c)
     if escape: raise SyntaxError(_('unterminated escape'))
     return fp.getvalue()