I have an input string, and I also have a vector of separators.
I want to output the vector of strings that are not in the separators and as an additional entry, tje separator that was found
So for example given
"AB<sep1>DE<sep1><sep2>" where "<sep1>" and "<sep2>" are separators
The output would be the vector
"AB", "<sep1>", "DE", "<sep1>", "<sep2>"
Is there an efficient way to implement this?
Here is a possible implementation.
And a minimal test.
It first finds and collects the positions of all instances of seperators in the string. Then it sorts them so we can iterate over the positions and extract all the substrings.
Note that this breaks down if one seperator contains another seperator as a substring, but I assume that would be a pathological case. It also breaks if a seperator is specified twice.