aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.com>2016-03-12 14:08:35 +0000
committerTim-Philipp Müller <tim@centricular.com>2016-03-12 14:15:54 +0000
commit3c8468cd4d90f5072934e849078298e70dd1ddfc (patch)
treed4447b0b2f6dd5a489c0f0d618b22ae42c7010af
parent02e84df0105fb50ab82441b7ec64de149d23b7f9 (diff)
downloadmeson-3c8468cd4d90f5072934e849078298e70dd1ddfc.zip
meson-3c8468cd4d90f5072934e849078298e70dd1ddfc.tar.gz
meson-3c8468cd4d90f5072934e849078298e70dd1ddfc.tar.bz2
Add string underscorify() function
So we can easily construct the defines for include headers and struct checks and such.
-rw-r--r--mesonbuild/interpreter.py2
-rw-r--r--test cases/common/42 string formatting/meson.build13
2 files changed, 15 insertions, 0 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 37432a8..14f20e7 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -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.')
diff --git a/test cases/common/42 string formatting/meson.build b/test cases/common/42 string formatting/meson.build
index ea785e8..56cbcb2 100644
--- a/test cases/common/42 string formatting/meson.build
+++ b/test cases/common/42 string formatting/meson.build
@@ -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.')