Original Post
Edited: My apologies, I was tied when I posted this and didn’t do a good job explaining my problem. When I past a pre-defined iterator into my parser function and try to compare it against one I created inside that parser function, the function would fail. But when I just past an offset value and created both iterators inside the function – it worked fine. So I’m not sure if I past the iterator correctly or not. I have another function that takes an iterator as a peramiter and that works fine, but it doesn’t compare the iterator to another iterator. So am I missing something about copies of iterators, or is this suppose to work and maybe I just did something dump in the original code and didn’t duplicate it in the example given? I just modified the code I had back to the way it was when it was failing, but didn't svn the failing code before modifying it =( Example: Edited: Fixed the problem by making ByteList::iterator ¤t [Edited by - MrRage on March 24, 2007 1:20:08 AM]
typedef std::vector<char> ByteVector;
typedef std::vector<std::string> ResultSet;
ResultSet Parser::split(ByteList msg, ByteList::iterator current) {
/////////////////////////////////////////
// Configure the ResultSet
ResultSet results;
ByteList::iterator end = msg.end();
ByteList::iterator next = current;
end -= 4; // lets skip over the '001*'
next++; // Because we want to see whats comming next with out moving
std::string item;
while (current != end) {
if (((*current) == ' ' || (*current) == ':' ) || next == end) {
if (item.length() > 0) {
string copy = item;
results.push_back(copy);
item = "";
}
} else {
item.push_back((*current));
}
current++;
next++;
}
return results;
}
...
ByteVector msg = someFunc(); // returns a 92 char long vector
ByteVector::iterator start = msg.begin();
start += 51;
ResultSet rs = Parser::split(msg, start);