pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43648?usp=email )
Change subject: library/Misc_Helpers: Introduce API f_str_oct_split() ......................................................................
library/Misc_Helpers: Introduce API f_str_oct_split()
Similar to existing f_str_split() but operating on octetstrings. It uses the external f_strstr_oct() function to look up in an efficient way.
This function will be used by HTTP2 code to split multipart data based on boundary specified in the HTTP2 Header.
Change-Id: Ie26062bf00133d25be4b41424186484d34b18dce --- M library/Misc_Helpers.ttcn 1 file changed, 21 insertions(+), 0 deletions(-)
Approvals: osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified laforge: Looks good to me, approved
diff --git a/library/Misc_Helpers.ttcn b/library/Misc_Helpers.ttcn index 967c8d1..24d0590 100644 --- a/library/Misc_Helpers.ttcn +++ b/library/Misc_Helpers.ttcn @@ -134,4 +134,25 @@ return parts; }
+/* Same as f_str_split() but using octetstring */ +type record of octetstring ro_octetstring; +function f_str_oct_split(octetstring str, octetstring delim := ''O) return ro_octetstring +{ + var integer pos := 0; + var ro_octetstring parts := {}; + var integer delim_pos; + var integer end := lengthof(str); + while (pos < end) { + delim_pos := f_strstr_oct(str, delim, pos); + if (delim_pos < 0) { + delim_pos := end; + } + if (delim_pos > pos) { + parts := parts & { substr(str, pos, delim_pos - pos) }; + } + pos := delim_pos + lengthof(delim); + } + return parts; +} + }