aboutsummaryrefslogtreecommitdiff
path: root/interpreter.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-10-15 18:40:00 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2015-10-15 18:40:00 +0300
commitdf979ad422709bc61d9bb05d49e0803b6f745efd (patch)
tree353e703e0afaad71d401492d054c98050d0044c7 /interpreter.py
parentcf5cefba0d2b6e76ed9371cfc65329f74f6f1ca4 (diff)
downloadmeson-df979ad422709bc61d9bb05d49e0803b6f745efd.zip
meson-df979ad422709bc61d9bb05d49e0803b6f745efd.tar.gz
meson-df979ad422709bc61d9bb05d49e0803b6f745efd.tar.bz2
String startswith and endswith methods.
Diffstat (limited to 'interpreter.py')
-rw-r--r--interpreter.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/interpreter.py b/interpreter.py
index 82fdb74..b9f91c4 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -1832,12 +1832,12 @@ class Interpreter():
def string_method_call(self, obj, method_name, args):
obj = self.to_native(obj)
+ (posargs, _) = self.reduce_arguments(args)
if method_name == 'strip':
return obj.strip()
elif method_name == 'format':
return self.format_string(obj, args)
elif method_name == 'split':
- (posargs, _) = self.reduce_arguments(args)
if len(posargs) > 1:
raise InterpreterException('Split() must have at most one argument.')
elif len(posargs) == 1:
@@ -1847,6 +1847,13 @@ class Interpreter():
return obj.split(s)
else:
return obj.split()
+ elif method_name == 'startswith' or method_name == 'endswith':
+ s = posargs[0]
+ if not isinstance(s, str):
+ raise InterpreterException('Argument must be a string.')
+ if method_name == 'startswith':
+ return obj.startswith(s)
+ return obj.endswith(s)
raise InterpreterException('Unknown method "%s" for a string.' % method_name)
def to_native(self, arg):