59 string::size_type index = s.find_first_not_of(delimiters, 0);
60 while (index != s.npos)
62 string::size_type newIndex = s.find_first_of(delimiters, index);
63 bool endBlockFound =
false;
64 while (!endBlockFound)
66 if (newIndex != s.npos)
68 string token = s.substr(index, newIndex - index);
73 tokens_.push_back(cache + token);
75 index = s.find_first_not_of(delimiters, newIndex);
81 cache += s.substr(index, newIndex - index + 1);
83 newIndex = s.find_first_of(delimiters, index);
88 string token = s.substr(index);
92 tokens_.push_back(cache + token);
98 throw Exception(
"NestedStringTokenizer (constructor). Unclosed block.");
105 string::size_type index = 0;
106 while (index != s.npos)
108 string::size_type newIndex = s.find(delimiters, index);
109 bool endBlockFound =
false;
110 while (!endBlockFound)
112 if (newIndex != s.npos)
114 string token = s.substr(index, newIndex - index);
119 tokens_.push_back(cache + token);
121 index = newIndex + delimiters.size();
122 endBlockFound =
true;
127 cache += s.substr(index, newIndex - index + 1);
128 index = newIndex + 1;
129 newIndex = s.find(delimiters, index);
134 string token = s.substr(index);
138 tokens_.push_back(cache + token);
141 endBlockFound =
true;
154 throw Exception(
"No more token in nested tokenizer.");
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
NestedStringTokenizer(const std::string &s, const std::string &open, const std::string &end, const std::string &delimiters=" \t\n\f\r", bool solid=false)
Build a new StringTokenizer from a string.
const std::string & nextToken()
Get the next available token. If no token is availbale, throw an Exception.
size_t currentPosition_
the current position in the token list.
bool hasMoreToken() const
Tell if some tokens are still available.
std::deque< std::string > tokens_
Where the tokens are stored.
std::size_t count(const std::string &s, const std::string &pattern)
Count the occurences of a given pattern in a string.