Move f_strstr_count() Osmocom_VTY_Functions.ttcn -> Misc_Helpers.ttcn
This is quite a generic string handling function which fits better
in a generic utility file like Misc_Helpers.ttcn.
Change-Id: I105844d2bcab6c24624be1224c1ba78b69d4b44c
diff --git a/library/Misc_Helpers.ttcn b/library/Misc_Helpers.ttcn
index dda2c2c..cbc1e70 100644
--- a/library/Misc_Helpers.ttcn
+++ b/library/Misc_Helpers.ttcn
@@ -1,6 +1,7 @@
module Misc_Helpers {
import from Native_Functions all;
+import from TCCConversion_Functions all;
modulepar {
charstring mp_osmo_repo := "nightly";
@@ -61,4 +62,21 @@
}
}
+/* Return a count of how many times sub_str occurs in str. */
+function f_strstr_count(in charstring str, in charstring sub_str) return integer
+{
+ var integer count := 0;
+ var integer pos := 0;
+
+ while (true) {
+ var integer at := f_strstr(str, sub_str, pos);
+ if (at < 0) {
+ break;
+ }
+ count := count + 1;
+ pos := at + 1;
+ }
+ return count;
+}
+
}