54 const std::string& delim) :
56 delim_(delim), returnTokens_(false), currentPos_(tokenString_.begin()),
57 end_(tokenString_.end()) {}
60 std::string::const_iterator& last,
61 const std::string& delim) :
62 tokenString_(first, last),
63 delim_(delim), returnTokens_(false), currentPos_(tokenString_.begin()),
64 end_(tokenString_.end()) {}
67 const std::string& delim,
70 delim_(delim), returnTokens_(returnTokens),
71 currentPos_(tokenString_.begin()), end_(tokenString_.end()) {}
73 bool StringTokenizer::isDelimiter(
const char c) {
74 return delim_.find(c) == std::string::npos ? false :
true;
78 std::string::const_iterator tmpIter = currentPos_;
83 while (tmpIter != end_ && isDelimiter(*tmpIter)) {
92 if (tmpIter == end_) {
break; }
95 while (tmpIter != end_ && !isDelimiter(*tmpIter)) {
106 if (currentPos_ == end_) {
108 }
else if (returnTokens_) {
111 std::string::const_iterator i = currentPos_;
115 while (i != end_ && isDelimiter(*i)) {
119 return i != end_ ? true :
false;
126 if (currentPos_ != end_) {
127 std::insert_iterator<std::string> insertIter(result, result.begin());
129 while (currentPos_ != end_ && isDelimiter(*currentPos_)) {
131 *insertIter++ = *currentPos_++;
138 while (currentPos_ != end_ && !isDelimiter(*currentPos_)) {
139 *insertIter++ = *currentPos_++;
147 if (currentPos_ != end_) {
148 while (currentPos_ != end_ && isDelimiter(*currentPos_)) {
157 while (currentPos_ != end_ && !isDelimiter(*currentPos_)) {
165 std::istringstream iss(token);
171 std::cerr <<
"unable to convert " << token <<
" to a bool" << std::endl;
181 return atoi(token.c_str());
186 convertFortranNumber(token);
187 return (
float)(atof(token.c_str()));
192 convertFortranNumber(token);
193 return atof(token.c_str());
198 std::string::const_iterator tmpIter = currentPos_;
200 if (tmpIter != end_) {
201 std::insert_iterator<std::string> insertIter(result, result.begin());
203 while (tmpIter != end_ && isDelimiter(*tmpIter)) {
205 *insertIter++ = *tmpIter++;
212 while (tmpIter != end_ && !isDelimiter(*tmpIter)) {
213 *insertIter++ = *tmpIter++;
221 std::vector<std::string> tokens;
228 void StringTokenizer::convertFortranNumber(std::string& fortranNumber) {
229 std::string::iterator i;
230 for (i = fortranNumber.begin(); i != fortranNumber.end(); ++i) {
231 if (*i ==
'd' || *i ==
'D') { *i =
'E'; }
237 std::string::const_iterator tmpIter = currentPos_;
238 if (tmpIter != end_) {
239 std::insert_iterator<std::string> insertIter(result, result.begin());
241 while (tmpIter != end_) {
242 *insertIter++ = *tmpIter++;
std::vector< std::string > getAllTokens()
Returns all of the tokens.
std::string peekNextToken()
Returns the next token without advancing the position of the StringTokenizer.
std::string nextToken()
Returns the next token from this string tokenizer.
void skipToken()
Skips the next token from this string tokenizer.
int countTokens()
Calculates the number of times that this tokenizer's nextToken method can be called before it generat...
int nextTokenAsInt()
Returns the next token from this string tokenizer as an integer.
float nextTokenAsFloat()
Returns the next token from this string tokenizer as a float.
bool hasMoreTokens()
Tests if there are more tokens available from this tokenizer's string.
StringTokenizer(const std::string &str, const std::string &delim=" ;\t\n\r")
Constructs a string tokenizer for the specified string.
std::string getRemainingString()
Returns the remaining unparsed string.
bool nextTokenAsBool()
Returns the next token from this string tokenizer as a bool.
RealType nextTokenAsDouble()
Returns the next token from this string tokenizer as a RealType.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.