From e0f7bca321ec2efd5e18c173e0efbbb5e0b799ae Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Thu, 19 Jan 2017 02:14:16 +0530 Subject: [PATCH] PICARD-923: Add startswith and endswith script functions --- picard/script.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/picard/script.py b/picard/script.py index 73e84664e..38c361bf7 100644 --- a/picard/script.py +++ b/picard/script.py @@ -684,6 +684,18 @@ def func_firstwords(parser, text, length): return text[:length].rsplit(' ', 1)[0] +def func_startswith(parser, text, pattern): + if text.startswith(pattern): + return "1" + return "0" + + +def func_endswith(parser, text, pattern): + if text.endswith(pattern): + return "1" + return "0" + + def func_truncate(parser, text, length): try: length = int(length) @@ -817,6 +829,8 @@ register_script_function(func_is_complete, "is_complete") register_script_function(func_firstalphachar, "firstalphachar") register_script_function(func_initials, "initials") register_script_function(func_firstwords, "firstwords") +register_script_function(func_startswith, "startswith") +register_script_function(func_endswith, "endswith") register_script_function(func_truncate, "truncate") register_script_function(func_swapprefix, "swapprefix", check_argcount=False) register_script_function(func_delprefix, "delprefix", check_argcount=False)