Medusa  1.1
Coordinate Free Mehless Method implementation
stdtypesutils.cpp
Go to the documentation of this file.
2 
8 namespace mm {
9 
10 std::vector<std::string> split(const std::string& str, const std::string& delim) {
11  assert_msg(!delim.empty(), "Delimiter must not be empty.");
12  std::vector<std::string> tokens;
13  size_t prev = 0, pos = 0;
14  do {
15  pos = str.find(delim, prev);
16  if (pos == std::string::npos) pos = str.length();
17  tokens.emplace_back(str.substr(prev, pos-prev));
18  prev = pos + delim.length();
19  } while (pos < str.length() && prev < str.length());
20  if (prev == str.length()) tokens.emplace_back("");
21  return tokens;
22 }
23 
24 std::vector<std::string> split(const std::string& str, char delim) {
25  return split(str, std::string(1, delim));
26 }
27 
29 std::string join(const std::vector<std::string>& parts, const std::string& joiner) {
30  if (parts.empty()) return "";
31  std::string result = parts[0];
32  int n = parts.size();
33  for (int i = 1; i < n; ++i) {
34  result += joiner + parts[i];
35  }
36  return result;
37 }
38 
39 std::string join(const std::vector<std::string>& parts, char joiner) {
40  return join(parts, std::string(1, joiner));
41 }
43 
44 } // namespace mm
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::join
std::string join(const std::vector< std::string > &parts, const std::string &joiner)
Joins a vector of strings back together.
stdtypesutils.hpp
mm::sh::str
std::string str(shape_flags f)
Convert shape flags to a string representation.
Definition: shape_flags.hpp:32
assert_msg
#define assert_msg(cond,...)
Assert with better error reporting.
Definition: assert.hpp:75
mm::split
std::vector< std::string > split(const std::string &s, const std::string &delim)
Splits string by delim, returning a vector of tokens (including empty).
Definition: stdtypesutils.cpp:10