hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Algorithms.cpp
Go to the documentation of this file.
1 #include "Algorithms.hpp"
2 
3 namespace HCE
4 {
5 namespace algorithms
6 {
7  std::vector<std::string> stringSplitter(const std::string &inString, const std::string &separator, bool useEmptyToken)
8  {
9  std::size_t pos = 0;
10  std::size_t prevPos = 0;
11 
12  std::vector<std::string> ret;
13  if(separator.empty())
14  {
15  ret.push_back(inString);
16  }
17  else
18  {
19  while((pos = inString.find(separator, pos)) != std::string::npos)
20  {
21  if(!(pos == prevPos && !useEmptyToken))
22  {
23  ret.push_back(inString.substr(prevPos, (pos - prevPos)));
24  }
25  pos += separator.length();
26  prevPos = pos;
27  }
28  if(!(inString.length() == prevPos && !useEmptyToken))
29  {
30  ret.push_back(inString.substr(prevPos, inString.length() - prevPos));
31  }
32  }
33  return ret;
34  }
35 }
36 }