22 string::size_type index = s.find_first_not_of(delimiters, 0);
23 while (index != s.npos)
25 string::size_type newIndex = s.find_first_of(delimiters, index);
26 bool endBlockFound =
false;
27 while (!endBlockFound)
29 if (newIndex != s.npos)
31 string token = s.substr(index, newIndex - index);
36 tokens_.push_back(cache + token);
38 index = s.find_first_not_of(delimiters, newIndex);
44 cache += s.substr(index, newIndex - index + 1);
46 newIndex = s.find_first_of(delimiters, index);
51 string token = s.substr(index);
55 tokens_.push_back(cache + token);
61 throw Exception(
"NestedStringTokenizer (constructor). Unclosed block.");
68 string::size_type index = 0;
69 while (index != s.npos)
71 string::size_type newIndex = s.find(delimiters, index);
72 bool endBlockFound =
false;
73 while (!endBlockFound)
75 if (newIndex != s.npos)
77 string token = s.substr(index, newIndex - index);
82 tokens_.push_back(cache + token);
84 index = newIndex + delimiters.size();
90 cache += s.substr(index, newIndex - index + 1);
92 newIndex = s.find(delimiters, index);
97 string token = s.substr(index);
101 tokens_.push_back(cache + token);
104 endBlockFound =
true;
117 throw Exception(
"No more token in nested tokenizer.");
bool hasMoreToken() const
Tell if some tokens are still available.
std::size_t count(const std::string &s, const std::string &pattern)
Count the occurences of a given pattern in a string.
std::deque< std::string > tokens_
Where the tokens are stored.
const std::string & nextToken()
Get the next available token. If no token is availbale, throw an Exception.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::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.
size_t currentPosition_
the current position in the token list.