aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase.py
diff options
context:
space:
mode:
authorStéphane Cerveau <scerveau@collabora.com>2020-07-09 12:34:34 +0200
committerXavier Claessens <xclaesse@gmail.com>2020-07-20 20:04:01 -0400
commit8f106a2b9a7824075e55d3f044f2c0c5dd3ee700 (patch)
tree95d4b7f319fb62f1321b5a15af91bb0e48e55a9a /mesonbuild/interpreterbase.py
parent804a71e8f2b7c1011c91bd016df435fc952677a0 (diff)
downloadmeson-8f106a2b9a7824075e55d3f044f2c0c5dd3ee700.zip
meson-8f106a2b9a7824075e55d3f044f2c0c5dd3ee700.tar.gz
meson-8f106a2b9a7824075e55d3f044f2c0c5dd3ee700.tar.bz2
string: add substring method
This method aims to offer a simple way to 'substring' an existing string with start and end values.
Diffstat (limited to 'mesonbuild/interpreterbase.py')
-rw-r--r--mesonbuild/interpreterbase.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 634f4f2..9f35601 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -1026,6 +1026,20 @@ The result of this is undefined and will become a hard error in a future Meson r
if not isinstance(cmpr, str):
raise InterpreterException('Version_compare() argument must be a string.')
return mesonlib.version_compare(obj, cmpr)
+ elif method_name == 'substring':
+ if len(posargs) > 2:
+ raise InterpreterException('substring() takes maximum two arguments.')
+ start = 0
+ end = len(obj)
+ if len (posargs) > 0:
+ if not isinstance(posargs[0], int):
+ raise InterpreterException('substring() argument must be an int')
+ start = posargs[0]
+ if len (posargs) > 1:
+ if not isinstance(posargs[1], int):
+ raise InterpreterException('substring() argument must be an int')
+ end = posargs[1]
+ return obj[start:end]
raise InterpreterException('Unknown method "%s" for a string.' % method_name)
def format_string(self, templ: str, args: T.List[TYPE_nvar]) -> str: