summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/util.h61
1 files changed, 0 insertions, 61 deletions
diff --git a/lib/util.h b/lib/util.h deleted file mode 100644 index 9db8678..0000000 --- a/lib/util.h +++ /dev/null
@@ -1,61 +0,0 @@
1#ifndef UTIL_H_15DDCA2D
2#define UTIL_H_15DDCA2D
3
4#include <string>
5#include <sstream>
6#include <iterator>
7
8namespace verbly {
9
10 template <class InputIterator>
11 std::string implode(InputIterator first, InputIterator last, std::string delimiter)
12 {
13 std::stringstream result;
14
15 for (InputIterator it = first; it != last; it++)
16 {
17 if (it != first)
18 {
19 result << delimiter;
20 }
21
22 result << *it;
23 }
24
25 return result.str();
26 }
27
28 template <class OutputIterator>
29 void split(std::string input, std::string delimiter, OutputIterator out)
30 {
31 while (!input.empty())
32 {
33 int divider = input.find(delimiter);
34 if (divider == std::string::npos)
35 {
36 *out = input;
37 out++;
38
39 input = "";
40 } else {
41 *out = input.substr(0, divider);
42 out++;
43
44 input = input.substr(divider+delimiter.length());
45 }
46 }
47 }
48
49 template <class Container>
50 Container split(std::string input, std::string delimiter)
51 {
52 Container result;
53
54 split(input, delimiter, std::back_inserter(result));
55
56 return result;
57 }
58
59};
60
61#endif /* end of include guard: UTIL_H_15DDCA2D */