From 0c96dbff3a1ae03541b6a1e3fd12b753081fae0e Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Mon, 25 Jan 2016 21:51:41 +0200 Subject: String to int conversion. Closes #362. --- mesonbuild/interpreter.py | 5 +++++ test cases/common/42 string formatting/meson.build | 2 ++ test cases/failing/25 int conversion/meson.build | 3 +++ 3 files changed, 10 insertions(+) create mode 100644 test cases/failing/25 int conversion/meson.build diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 4894ac7..0a321a2 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2019,6 +2019,11 @@ class Interpreter(): if method_name == 'startswith': return obj.startswith(s) return obj.endswith(s) + elif method_name == 'to_int': + try: + return int(obj) + except Exception: + raise InterpreterException('String can not be converted to int: ' + obj) raise InterpreterException('Unknown method "%s" for a string.' % method_name) def to_native(self, arg): diff --git a/test cases/common/42 string formatting/meson.build b/test cases/common/42 string formatting/meson.build index 81f5268..39737f7 100644 --- a/test cases/common/42 string formatting/meson.build +++ b/test cases/common/42 string formatting/meson.build @@ -40,3 +40,5 @@ endif if long.endswith(prefix) error('Not suffix.') endif + +assert('3'.to_int() == 3, 'String int conversion does not work.') diff --git a/test cases/failing/25 int conversion/meson.build b/test cases/failing/25 int conversion/meson.build new file mode 100644 index 0000000..51f6c7e --- /dev/null +++ b/test cases/failing/25 int conversion/meson.build @@ -0,0 +1,3 @@ +project('int conversion', 'c') + +'notanumber'.to_int() -- cgit v1.1