58 string::size_type index = s.find_first_not_of(delimiters, 0);
59 while (index != s.npos)
61 string::size_type newIndex = s.find_first_of(delimiters, index);
62 bool endBlockFound =
false;
63 while (!endBlockFound)
65 if (newIndex != s.npos)
67 string token = s.substr(index, newIndex - index);
72 tokens_.push_back(cache + token);
74 index = s.find_first_not_of(delimiters, newIndex);
80 cache += s.substr(index, newIndex - index + 1);
82 newIndex = s.find_first_of(delimiters, index);
87 string token = s.substr(index);
91 tokens_.push_back(cache + token);
96 else throw Exception(
"NestedStringTokenizer (constructor). Unclosed block.");
103 string::size_type index = 0;
104 while (index != s.npos)
106 string::size_type newIndex = s.find(delimiters, index);
107 bool endBlockFound =
false;
108 while (!endBlockFound)
110 if (newIndex != s.npos)
112 string token = s.substr(index, newIndex - index);
117 tokens_.push_back(cache + token);
119 index = newIndex + delimiters.size();
120 endBlockFound =
true;
125 cache += s.substr(index, newIndex - index + 1);
126 index = newIndex + 1;
127 newIndex = s.find(delimiters, index);
132 string token = s.substr(index);
136 tokens_.push_back(cache + token);
139 endBlockFound =
true;
150 if (!hasMoreToken())
throw Exception(
"No more token in nested tokenizer.");
151 return tokens_[currentPosition_++];
This class allows to perform a correspondence analysis.
static unsigned int count(const std::string &s, const std::string &pattern)
Count the occurences of a given pattern in a string.
const std::string & nextToken()
Get the next available token. If no token is availbale, throw an Exception.
NestedStringTokenizer(const std::string &s, const std::string &open, const std::string &end, const std::string &delimiters=" \\", bool solid=false)
Build a new StringTokenizer from a string.