pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38025?usp=email )
Change subject: Misc_Helpers: Introduce API helper f_str_startswith ......................................................................
Misc_Helpers: Introduce API helper f_str_startswith
Counterpart of f_str_endswith(), this API is usually available in several programming languages like python, and it's handy to have since it's usually used and hence dev doesn't need to think on how to implement it using regexp, etc.
This API will be used in a follow-up patch implementing Prometheus metrics checker module.
Change-Id: Iad392ac652714a54a25954ea697f082d55772aa8 --- M library/Misc_Helpers.ttcn 1 file changed, 10 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/25/38025/1
diff --git a/library/Misc_Helpers.ttcn b/library/Misc_Helpers.ttcn index a742b0b..967c8d1 100644 --- a/library/Misc_Helpers.ttcn +++ b/library/Misc_Helpers.ttcn @@ -79,6 +79,16 @@ return count; }
+/* Return true if str starts exactly with token: */ +function f_str_startswith(charstring str, charstring token) return boolean +{ + if (lengthof(str) < lengthof(token)) { + return false; + } + var charstring str_start := substr(str, 0, lengthof(token)); + return str_start == token; +} + /* Return true if str ends exactly with token: */ function f_str_endswith(charstring str, charstring token) return boolean {