Join() convenience method for strings. Closes #552.

pull/556/head
Jussi Pakkanen 9 years ago
parent 1a0938cc25
commit 2a3a1ce8e0
  1. 6
      mesonbuild/interpreter.py
  2. 4
      test cases/common/42 string formatting/meson.build

@ -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):

@ -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')

Loading…
Cancel
Save