I've written a sort of... parser, for lack of a better term. What this simple function does is take a string, look for ANY AND ALL control codes (denoted by starting with "[" and ending with "]"), and pass them on to a seperate function to be executed, right before deleting them from the string.
Now, I've noticed that whenever I use string::erase, it throws off any further iterations through the string. Observe:
Code:
string str = "Hey! It's a[1][01 45 00 01] test string.";
for(uint i = 0; i < str.length(); i++){
if(str.at(i) == '['){
const uint eb = str.find_first_of(']');
if(eb != max_int and eb > i){ //begin capture sequence
executeControlCode(str.substr(i + 1, (eb - i) - 1));
str.erase(i, (eb - i) + 1);
}
}
}
Output:
"Hey! It's a[01 45 00 01] test string."
It captures the first control code properly, but not the second one... help with this?
EDIT: Wait a minute, if I place any sort of character between the 1st and 2nd control code, it captures both of them properly; why?!?