From c83106ee38048acbe737ef112e8d51c9b5bd42d7 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Sun, 7 Mar 2021 22:59:21 -0600 Subject: Add str.replace() method --- mesonbuild/interpreterbase.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'mesonbuild/interpreterbase.py') diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index aba9ed4..026eaf2 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -1192,6 +1192,13 @@ The result of this is undefined and will become a hard error in a future Meson r raise InterpreterException('substring() argument must be an int') end = posargs[1] return obj[start:end] + elif method_name == 'replace': + FeatureNew.single_use('str.replace', '0.58.0', self.subproject) + if len(posargs) != 2: + raise InterpreterException('replace() takes exactly two arguments.') + if not isinstance(posargs[0], str) or not isinstance(posargs[1], str): + raise InterpreterException('replace() requires that both arguments be strings') + return obj.replace(posargs[0], posargs[1]) raise InterpreterException('Unknown method "%s" for a string.' % method_name) def format_string(self, templ: str, args: T.List[TYPE_nvar]) -> str: -- cgit v1.1