Add string underscorify() function

So we can easily construct the defines for include headers and
struct checks and such.
pull/443/head
Tim-Philipp Müller 9 years ago
parent 02e84df010
commit 3c8468cd4d
  1. 2
      mesonbuild/interpreter.py
  2. 13
      test cases/common/42 string formatting/meson.build

@ -2037,6 +2037,8 @@ class Interpreter():
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.')

@ -65,4 +65,17 @@ 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.')

Loading…
Cancel
Save