summaryrefslogtreecommitdiff
path: root/src/utils/string.cpp
blob: 41e4224e9626ffa3baee02faae7ddc9bf87b029c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "string.hpp"

#include <sstream>
#include <string>
#include <vector>

std::vector<std::string> split_text(const std::string &text, char delimiter) {
  std::vector<std::string> parts;

  std::istringstream iss(text);
  std::string part;

  while (std::getline(iss, part, delimiter)) {
    parts.push_back(part);
  }

  return parts;
}

std::string join_vector(const std::vector<std::string> &vec, char delimiter) {
  std::string str;

  for (auto i = vec.begin(); i != vec.end() - 1; i++) {
    str += *i + delimiter;
  }

  str += vec[vec.size() - 1];

  return str;
}

std::string join_vector(const std::vector<std::string> &vec) {
  std::string str;

  for (const auto &e : vec) {
    str += e;
  }

  return str;
}