diff options
author | Bert Belder <bertbelder@gmail.com> | 2018-09-25 14:45:27 -0700 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2018-09-26 09:52:30 -0700 |
commit | 023b4640fc4c8bf3efd4f5f8914552cdae6d142b (patch) | |
tree | 89051ecaf1a2cbe147d01501288533881e32a1be /tools/setup.py | |
parent | 1b9424e9d78990100ac82697a20515f9cb9e8335 (diff) |
tools/setup: add gn_string() utility function
Diffstat (limited to 'tools/setup.py')
-rwxr-xr-x | tools/setup.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/setup.py b/tools/setup.py index 1f065769a..1a0b491c0 100755 --- a/tools/setup.py +++ b/tools/setup.py @@ -54,6 +54,18 @@ gn_args_header = [ ] +def gn_string(s): + # In gn, strings are enclosed in double-quotes and use backslash as the + # escape character. The only escape sequences supported are: + # \" (for literal quote) + # \$ (for literal dollars sign) + # \\ (for literal backslash) + # Any other use of a backslash is treated as a literal backslash. + s = re.sub(r'("|\$|\\(?=["$\\]))', r'\\\1', s) + s = '"' + s + '"' + return s + + def gn_args_are_generated(lines): for line in lines: if re.match("^\s*#.*REMOVE THIS LINE", line): |