Misc_Helpers.ttcn: Add some more string handling API helpers
These are currently used by code in AMI_Functions doing some workaround for TEXT decoder limitations. They can be merged independently now since anyway they are totally generic and may be useful for future users. Change-Id: I3d6da125a10807b7a2f3ecad8145a046a322c7d6
This commit is contained in:
parent
4362dbd088
commit
9c83471a5b
|
@ -79,6 +79,31 @@ function f_strstr_count(in charstring str, in charstring sub_str) return integer
|
|||
return count;
|
||||
}
|
||||
|
||||
/* Return true if str ends exactly with token: */
|
||||
function f_str_endswith(charstring str, charstring token) return boolean
|
||||
{
|
||||
if (lengthof(str) < lengthof(token)) {
|
||||
return false;
|
||||
}
|
||||
var charstring str_end := substr(str, lengthof(str) - lengthof(token), lengthof(token));
|
||||
return str_end == token;
|
||||
}
|
||||
|
||||
/* Replace all matches of token "find" with "repl" in "str" */
|
||||
function f_str_replace(charstring str, charstring find, charstring repl) return charstring
|
||||
{
|
||||
var integer pos := f_strstr(str, find, 0);
|
||||
if (pos < 0) {
|
||||
return str;
|
||||
}
|
||||
var charstring prefix := substr(str, 0, pos);
|
||||
var integer suffix_pos := pos + lengthof(find);
|
||||
var charstring suffix := substr(str, suffix_pos, lengthof(str) - suffix_pos);
|
||||
|
||||
var charstring new_str := prefix & repl & f_str_replace(suffix, find, repl);
|
||||
return new_str;
|
||||
}
|
||||
|
||||
type record of charstring ro_charstring;
|
||||
function f_str_split(charstring str, charstring delim := "\n") return ro_charstring
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue