add escaping function to python module
authorEvan Martin <martine@danga.com>
Tue, 9 Aug 2011 20:21:21 +0000 (13:21 -0700)
committerEvan Martin <martine@danga.com>
Tue, 16 Aug 2011 18:35:56 +0000 (11:35 -0700)
misc/ninja.py

index abde596..7fa4bf1 100644 (file)
@@ -84,3 +84,11 @@ class Writer(object):
         if isinstance(input, list):
             return input
         return [input]
+
+
+def escape(string):
+    """Escape a string such that it can be embedded into a Ninja file without
+    further interpretation."""
+    assert '\n' not in string, 'Ninja syntax does not allow newlines'
+    # We only have one special metacharacter: '$'.
+    return string.replace('$', '$$')