-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringTokenizer.cpp
More file actions
41 lines (38 loc) · 1.08 KB
/
StringTokenizer.cpp
File metadata and controls
41 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "StringTokenizer.h"
using std::string;
/** Position start and end so that start is the index of the start
of the next token and end is the end.
*/
void String_Tokenizer::find_next() {
// Find the first character that is not a delimeter
/*<snippet id="1" omit="false">*/
start = the_source.find_first_not_of(the_delim, end);
/*</snippet>*/
// Find the next delimeter
/*<snippet id="2" omit="false">*/
end = the_source.find_first_of(the_delim, start);
/*</snippet>*/
}
/** Determine if there are more tokens
@return true if there are more tokens
*/
bool String_Tokenizer::has_more_tokens() {
return start != string::npos;
}
/** Retrieve the next token
@return the next token. If there are no more
tokens, an empty string is returned
*/
string String_Tokenizer::next_token() {
// Make sure there is a next token
if (!has_more_tokens())
return "";
// Save the next token in return_value
/*<snippet id="3" omit="false">*/
string token = the_source.substr(start, end - start);
/*</snippet>*/
// Find the following token
find_next();
// Return the next token
return token;
}