PICARD-923: Add startswith and endswith script functions

This commit is contained in:
Sambhav Kothari
2017-01-19 02:14:16 +05:30
parent a24f26e941
commit e0f7bca321

View File

@@ -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)