Created
March 14, 2011 17:04
-
-
Save dreamiurg/869465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void tokenize(const string& instr, Tokens& tokens) | |
{ | |
// trim spaces & not valid chars | |
string str; | |
trim_acс trimmer(str); | |
for_each(instr.begin(), instr.end(), trimmer); | |
string::size_type numPos = str.find_first_of(NUMS, 0); | |
string::size_type endPos = str.find_first_not_of(NUMS, numPos); | |
string::size_type opPos; | |
while (std::string::npos != endPos || std::string::npos != numPos) | |
{ | |
// push number | |
tokens.push_back(str.substr(numPos, endPos - numPos)); | |
// find & push op | |
opPos = str.find_first_of(OPS, endPos); | |
if (std::string::npos != opPos) | |
{ | |
tokens.push_back(str.substr(opPos, 1)); | |
} | |
numPos = str.find_first_of(NUMS, opPos); | |
endPos = str.find_first_not_of(NUMS, numPos); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment