Last change
on this file since 663 was
659,
checked in by nicolasc, 17 years ago
|
- a lot of inlining of getfunctions
- set libaudio to shared (not sure, if related: audioplayer + ingame sound == crash!)
- minor space cleanups
|
File size:
1.1 KB
|
Line | |
---|
1 | #ifndef __TOKEINZER_H__ |
---|
2 | #define __TOKEINZER_H__ |
---|
3 | |
---|
4 | #include <string> |
---|
5 | #include <iostream> |
---|
6 | |
---|
7 | /** |
---|
8 | * String tokenizer |
---|
9 | * |
---|
10 | * Splits a given string into several smaller strings |
---|
11 | * using a delmiter (default is the comma). |
---|
12 | * Returns the result as a vector<string> object |
---|
13 | * |
---|
14 | * @author Nicolas Perrenoud<nicolape@ee.ethz.ch> |
---|
15 | */ |
---|
16 | |
---|
17 | inline std::vector<std::string> tokenize(const std::string& str, const std::string& delimiters = ",") |
---|
18 | { |
---|
19 | std::vector<std::string> tokens; |
---|
20 | |
---|
21 | // Skip delimiters at beginning. |
---|
22 | std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); |
---|
23 | // Find first "non-delimiter". |
---|
24 | std::string::size_type pos = str.find_first_of(delimiters, lastPos); |
---|
25 | |
---|
26 | while (std::string::npos != pos || std::string::npos != lastPos) |
---|
27 | { |
---|
28 | // Found a token, add it to the vector. |
---|
29 | tokens.push_back(str.substr(lastPos, pos - lastPos)); |
---|
30 | // Skip delimiters. Note the "not_of" |
---|
31 | lastPos = str.find_first_not_of(delimiters, pos); |
---|
32 | // Find next "non-delimiter" |
---|
33 | pos = str.find_first_of(delimiters, lastPos); |
---|
34 | } |
---|
35 | return tokens; |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.