Alright, here's the problem. I have a simple function that takes an input string, a starting delimeter and an ending delimeter, and returns the string in between.
Code:
std::string getBetween(std::string buffer, std::string first, std::string second)
{
std::string input = buffer;
std::string output;
int fpos = input.find(first, 0);
int spos = input.find(second, fpos);
fpos += 1;
spos -= 1;
int length = (spos - fpos) + 1;
std::cout<<"POS: "<<fpos<<" - "<<spos<<"\n";
std::cout<<"INPUT: "<<input<<"\n";
output = input.substr(fpos, length);
std::cout<<"OUTPUT: "<<output<<"\n\n";
return output;
}
It works fine except for a particular case. This is the output I get:
Code:
POS: 4 - 9
INPUT: var(newvar);
OUTPUT: newvar
POS: 4 - 35
INPUT: set(newvar, "testing print function");
OUTPUT: newvar, "testing print function"
POS: 1 - -1
INPUT: "testing print function"
OUTPUT: testing print function"
POS: 6 - 11
INPUT: print(newvar);
OUTPUT: newvar
POS: 0 - -2
INPUT: END;
OUTPUT: END;
The problem is in the 3rd section (and the last one too, though that doesn't matter so much). I don't know why this is happening, could it be a problem with the input or is it the function itself? Any help would be appreciated.
edit: Arghh! I think I just realised the problem within about 10 seconds of posting! I forgot to check if it was found or not!! >.<
Alright I got it fixed, problem was I was searching for the end string starting from fpos instead of fpos+1!