diff options
author | Tim-Philipp Müller <tim@centricular.com> | 2016-09-12 22:05:19 +0100 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2016-09-13 23:44:33 +0100 |
commit | 09fdc7f815d8b6dede94a14a15a0c05fd1a621c1 (patch) | |
tree | 163373ee92e806c83438e4d4e62c8229006fb176 /mesonbuild/interpreter.py | |
parent | 49583ccfabcc3db057521bf2801f75f5bab94e0e (diff) | |
download | meson-09fdc7f815d8b6dede94a14a15a0c05fd1a621c1.zip meson-09fdc7f815d8b6dede94a14a15a0c05fd1a621c1.tar.gz meson-09fdc7f815d8b6dede94a14a15a0c05fd1a621c1.tar.bz2 |
configuration_data: add .set_quoted() convenience method to set quoted string
Quotes in the string will be escaped C-string style with \", but
nothing else will be escaped.
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r-- | mesonbuild/interpreter.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 9584950..316f8c4 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -187,6 +187,7 @@ class ConfigurationDataHolder(InterpreterObject): self.held_object = build.ConfigurationData() self.methods.update({'set': self.set_method, 'set10': self.set10_method, + 'set_quoted': self.set_quoted_method, 'has' : self.has_method, }) @@ -211,6 +212,13 @@ class ConfigurationDataHolder(InterpreterObject): (name, val) = self.validate_args(args) self.held_object.values[name] = val + def set_quoted_method(self, args, kwargs): + (name, val) = self.validate_args(args) + if not isinstance(val, str): + raise InterpreterException("Second argument to set_quoted must be a string.") + escaped_val = '\\"'.join(val.split('"')) + self.held_object.values[name] = '"' + escaped_val + '"' + def set10_method(self, args, kwargs): (name, val) = self.validate_args(args) if val: |