##// END OF EJS Templates
templater: simplify parsestring
Matt Mackall -
r3639:5c9a3621 default
parent child Browse files
Show More
@@ -14,13 +14,9 b' def parsestring(s, quoted=True):'
14 '''parse a string using simple c-like syntax.
14 '''parse a string using simple c-like syntax.
15 string must be in quotes if quoted is True.'''
15 string must be in quotes if quoted is True.'''
16 if quoted:
16 if quoted:
17 first = s[0]
17 if len(s) < 2 or s[0] != s[-1]:
18 if len(s) < 2: raise SyntaxError(_('string too short'))
18 raise SyntaxError(_('unmatched quotes'))
19 if first not in "'\"": raise SyntaxError(_('invalid quote'))
19 return s[1:-1].decode('string_escape')
20 if s[-1] != first: raise SyntaxError(_('unmatched quotes'))
21 s = s[1:-1].decode('string_escape')
22 if first in s: raise SyntaxError(_('string ends early'))
23 return s
24
20
25 return s.decode('string_escape')
21 return s.decode('string_escape')
26
22
General Comments 0
You need to be logged in to leave comments. Login now