diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-05-24 23:06:20 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-05-24 23:06:20 +0300 |
commit | 2a3a1ce8e001042f8b5018affc75e953da58bb26 (patch) | |
tree | 99a7d2b4cc1826ef92daf861f83ab3d91d5f4bd7 | |
parent | 1a0938cc250d6202ffb099fba40b58fb5880c90c (diff) | |
download | meson-2a3a1ce8e001042f8b5018affc75e953da58bb26.zip meson-2a3a1ce8e001042f8b5018affc75e953da58bb26.tar.gz meson-2a3a1ce8e001042f8b5018affc75e953da58bb26.tar.bz2 |
Join() convenience method for strings. Closes #552.
-rw-r--r-- | mesonbuild/interpreter.py | 6 | ||||
-rw-r--r-- | test cases/common/42 string formatting/meson.build | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index ca437c6..ae119de 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2109,6 +2109,12 @@ class Interpreter(): return int(obj) except Exception: raise InterpreterException('String can not be converted to int: ' + obj) + elif method_name == 'join': + if len(posargs) != 1: + raise InterpreterException('Join() takes exactly one argument.') + strlist = posargs[0] + check_stringlist(strlist) + return obj.join(strlist) 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 c2ee151..0d17448 100644 --- a/test cases/common/42 string formatting/meson.build +++ b/test cases/common/42 string formatting/meson.build @@ -51,3 +51,7 @@ assert(false.to_string() == 'false', 'bool string conversion failed') assert(true.to_string('yes', 'no') == 'yes', 'bool string conversion with args failed') assert(false.to_string('yes', 'no') == 'no', 'bool string conversion with args failed') assert('@0@'.format(true) == 'true', 'bool string formatting failed') + +assert(' '.join(['a', 'b', 'c']) == 'a b c', 'join() array broken') +assert(''.join(['a', 'b', 'c']) == 'abc', 'empty join() broken') +assert(' '.join(['a']) == 'a', 'single join broken') |