Mercurial > hg
changeset 1902:1cc5f25653a3
make parsestring work with strings that do not have quotes.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Mon, 27 Feb 2006 11:18:56 -0800 |
parents | c64bef3d7043 |
children | e4abeafd6eb1 |
files | mercurial/templater.py |
diffstat | 1 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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()