diff options
-rw-r--r-- | authors.txt | 1 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 10 | ||||
-rw-r--r-- | test cases/common/42 string formatting/meson.build | 37 |
3 files changed, 47 insertions, 1 deletions
diff --git a/authors.txt b/authors.txt index 5f79881..d8b0abc 100644 --- a/authors.txt +++ b/authors.txt @@ -32,3 +32,4 @@ Nirbheek Chauhan Nicolas Schneider Luke Adams Rogiel Sulzbach +Tim-Philipp Müller diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 62b7fc0..14f20e7 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2033,6 +2033,12 @@ class Interpreter(): return obj.strip() elif method_name == 'format': return self.format_string(obj, args) + elif method_name == 'to_upper': + return obj.upper() + elif method_name == 'to_lower': + return obj.lower() + elif method_name == 'underscorify': + return re.sub(r'[^a-zA-Z0-9]', '_', obj) elif method_name == 'split': if len(posargs) > 1: raise InterpreterException('Split() must have at most one argument.') @@ -2043,12 +2049,14 @@ class Interpreter(): return obj.split(s) else: return obj.split() - elif method_name == 'startswith' or method_name == 'endswith': + elif method_name == 'startswith' or method_name == 'contains' 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) + elif method_name == 'contains': + return obj.find(s) >= 0 return obj.endswith(s) elif method_name == 'to_int': try: diff --git a/test cases/common/42 string formatting/meson.build b/test cases/common/42 string formatting/meson.build index 39737f7..56cbcb2 100644 --- a/test cases/common/42 string formatting/meson.build +++ b/test cases/common/42 string formatting/meson.build @@ -41,4 +41,41 @@ if long.endswith(prefix) error('Not suffix.') endif +if not long.contains(prefix) + error('Does not contain prefix') +endif + +if not long.contains(suffix) + error('Does not contain suffix') +endif + +if not long.contains('bcd') + error('Does not contain middle part') +endif + +if long.contains('dc') + error('Broken contains') +endif + +if long.to_upper() != 'ABCDE' + error('Broken to_upper') +endif + +if long.to_upper().to_lower() != long + error('Broken to_lower') +endif + +if 'struct stat.st_foo'.underscorify() != 'struct_stat_st_foo' + error('Broken underscorify') +endif + +if '#include <foo/bar.h>'.underscorify() != '_include__foo_bar_h_' + error('Broken underscorify') +endif + +# case should not change, space should be replaced, numbers are ok too +if 'Do SomeThing 09'.underscorify() != 'Do_SomeThing_09' + error('Broken underscorify') +endif + assert('3'.to_int() == 3, 'String int conversion does not work.') |