blob: dfaaa8724feeaa17b056b2b189d0d9899e456714 (
plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright 2008 Nanorex, Inc. See LICENSE file for details.
#include "Nanorex/Utility/NXStringTokenizer.h"
namespace Nanorex {
/* CONSTRUCTOR */
/**
* Constructs a tokenizer for the given line delimited with the given
* delimiters. For example, the string foo;bar;baz; has three tokens
* delimited with semi-colons.
*/
NXStringTokenizer::NXStringTokenizer(const std::string& line,
const std::string& delimiters) {
inString = line;
this->delimiters = delimiters;
inStringLength = inString.length();
position = 0;
}
/* FUNCTION: getNextToken */
/**
* Returns the next token encountered in the string.
*/
std::string NXStringTokenizer::getNextToken() {
int tokenStart = position;
int tokenLength = 0;
while ((delimiters.find(inString[position]) == std::string::npos) &&
(position < inStringLength)) {
tokenLength++;
position++;
}
std::string token = inString.substr(tokenStart, tokenLength);
position++;
return token;
}
/* FUNCTION: hasMoreTokens */
/**
* Returns whether or not there are more tokens in the string.
*/
bool NXStringTokenizer::hasMoreTokens() {
int index = position;
if (index < inStringLength)
return true;
else
return false;
}
} // Nanorex::
|