Last change
on this file since 8538 was
8531,
checked in by patrick, 18 years ago
|
orxonox: added a tokenizer class for strings and working on parsing of the md3 config file
|
File size:
853 bytes
|
Rev | Line | |
---|
[8531] | 1 | /** |
---|
| 2 | * @file tokenizer.cc |
---|
| 3 | * @brief a tokenizer class |
---|
| 4 | * |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | #include "tokenizer.h" |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | /** |
---|
| 11 | * tokenize a string |
---|
| 12 | */ |
---|
| 13 | void Tokenizer::tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters) |
---|
| 14 | { |
---|
| 15 | // Skip delimiters at beginning. |
---|
| 16 | std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); |
---|
| 17 | // Find first "non-delimiter". |
---|
| 18 | std::string::size_type pos = str.find_first_of(delimiters, lastPos); |
---|
| 19 | |
---|
| 20 | while (std::string::npos != pos || std::string::npos != lastPos) |
---|
| 21 | { |
---|
| 22 | // Found a token, add it to the vector. |
---|
| 23 | tokens.push_back(str.substr(lastPos, pos - lastPos)); |
---|
| 24 | // Skip delimiters. Note the "not_of" |
---|
| 25 | lastPos = str.find_first_not_of(delimiters, pos); |
---|
| 26 | // Find next "non-delimiter" |
---|
| 27 | pos = str.find_first_of(delimiters, lastPos); |
---|
| 28 | } |
---|
| 29 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.