Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revset.py @ 12408:78a97859b90d
revset: support raw string literals
This adds support for r'...' and r"..." as string literals. Strings
with the "r" prefix will not have their escape characters interpreted.
This is especially useful for grep(), where, with regular string
literals, \number is interpreted as an octal escape code, and \b is
interpreted as the backspace character (\x08).
author | Brodie Rao <brodie@bitheap.org> |
---|---|
date | Fri, 24 Sep 2010 15:36:53 -0500 |
parents | 4cdaf1adafc8 |
children | 64db820c66a2 |
line wrap: on
line diff
--- a/mercurial/revset.py Sun Sep 26 13:11:31 2010 -0500 +++ b/mercurial/revset.py Fri Sep 24 15:36:53 2010 -0500 @@ -48,7 +48,14 @@ pos += 1 # skip ahead elif c in "():,-|&+!": # handle simple operators yield (c, None, pos) - elif c in '"\'': # handle quoted strings + elif (c in '"\'' or c == 'r' and + program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings + if c == 'r': + pos += 1 + c = program[pos] + decode = lambda x: x + else: + decode = lambda x: x.decode('string-escape') pos += 1 s = pos while pos < l: # find closing quote @@ -57,7 +64,7 @@ pos += 2 continue if d == c: - yield ('string', program[s:pos].decode('string-escape'), s) + yield ('string', decode(program[s:pos]), s) break pos += 1 else: