83 |
|
} |
84 |
|
|
85 |
|
bool StringTokenizer::hasMoreTokens() { |
86 |
+ |
|
87 |
+ |
if (currentPos_ == end_) { |
88 |
+ |
return false; |
89 |
+ |
} else if (returnTokens_) { |
90 |
+ |
return true; |
91 |
+ |
} else { |
92 |
+ |
std::string::iterator i = currentPos_; |
93 |
|
|
94 |
< |
return currentPos_ != end_ ? true : false; |
94 |
> |
//walk through the remaining string to check whether it contains non-delimeter or not |
95 |
> |
while(i != end_ && isDelimiter(*i)) { |
96 |
> |
++i; |
97 |
> |
} |
98 |
> |
|
99 |
> |
return i != end_ ? true : false; |
100 |
> |
} |
101 |
|
} |
102 |
|
|
103 |
|
std::string StringTokenizer::nextToken() { |
104 |
< |
string result; |
104 |
> |
std::string result; |
105 |
|
|
106 |
|
if(currentPos_ != end_) { |
107 |
|
std::insert_iterator<string> insertIter(result, result.begin()); |
126 |
|
} |
127 |
|
|
128 |
|
int StringTokenizer::nextTokenAsInt() { |
129 |
< |
return atoi(nextToken().c_str()); |
129 |
> |
std::string token = nextToken(); |
130 |
> |
std::istringstream iss(token); |
131 |
> |
int result; |
132 |
> |
|
133 |
> |
if (iss >> result) { |
134 |
> |
return result; |
135 |
> |
} else { |
136 |
> |
std::err << "unable to convert " << token << "to an integer" << std::endl; |
137 |
> |
return 0; |
138 |
> |
} |
139 |
|
} |
140 |
|
|
141 |
|
float StringTokenizer::nextTokenAsFloat() { |
142 |
< |
return atof(nextToken().c_str()); |
142 |
> |
std::string token = nextToken(); |
143 |
> |
std::istringstream iss(token); |
144 |
> |
float result; |
145 |
> |
|
146 |
> |
if (iss >> result) { |
147 |
> |
return result; |
148 |
> |
} else { |
149 |
> |
std::err << "unable to convert " << token << "to a float" << std::endl; |
150 |
> |
return 0.0; |
151 |
> |
} |
152 |
|
} |
153 |
|
|
154 |
+ |
double StringTokenizer::nextTokenAsDouble() { |
155 |
+ |
std::string token = nextToken(); |
156 |
+ |
std::istringstream iss(token); |
157 |
+ |
double result; |
158 |
+ |
|
159 |
+ |
if (iss >> result) { |
160 |
+ |
return result; |
161 |
+ |
} else { |
162 |
+ |
std::err << "unable to convert " << token << "to a double" << std::endl; |
163 |
+ |
return 0.0; |
164 |
+ |
} |
165 |
+ |
} |
166 |
+ |
|
167 |
|
std::string StringTokenizer::peekNextToken() { |
168 |
|
string result; |
169 |
|
std::string::const_iterator tmpIter = currentPos_; |