From 09fdc7f815d8b6dede94a14a15a0c05fd1a621c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 12 Sep 2016 22:05:19 +0100 Subject: 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. --- mesonbuild/interpreter.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'mesonbuild/interpreter.py') 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: -- cgit v1.1