diff options
Diffstat (limited to 'util.h')
-rw-r--r-- | util.h | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/util.h b/util.h deleted file mode 100644 index 5d16649..0000000 --- a/util.h +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | #ifndef UTIL_H_CED7A66D | ||
2 | #define UTIL_H_CED7A66D | ||
3 | |||
4 | #include <algorithm> | ||
5 | #include <string> | ||
6 | #include <iterator> | ||
7 | #include <cctype> | ||
8 | #include <sstream> | ||
9 | |||
10 | namespace cadence { | ||
11 | |||
12 | inline std::string uppercase(std::string in) | ||
13 | { | ||
14 | std::string result; | ||
15 | std::transform(std::begin(in), std::end(in), std::back_inserter(result), [] (char ch) | ||
16 | { | ||
17 | return std::toupper(ch); | ||
18 | }); | ||
19 | |||
20 | return result; | ||
21 | } | ||
22 | |||
23 | template <class InputIterator> | ||
24 | std::string implode(InputIterator first, InputIterator last, std::string delimiter) | ||
25 | { | ||
26 | std::stringstream result; | ||
27 | |||
28 | for (InputIterator it = first; it != last; it++) | ||
29 | { | ||
30 | if (it != first) | ||
31 | { | ||
32 | result << delimiter; | ||
33 | } | ||
34 | |||
35 | result << *it; | ||
36 | } | ||
37 | |||
38 | return result.str(); | ||
39 | } | ||
40 | |||
41 | template <class OutputIterator> | ||
42 | void split(std::string input, std::string delimiter, OutputIterator out) | ||
43 | { | ||
44 | while (!input.empty()) | ||
45 | { | ||
46 | int divider = input.find(delimiter); | ||
47 | if (divider == std::string::npos) | ||
48 | { | ||
49 | *out = input; | ||
50 | out++; | ||
51 | |||
52 | input = ""; | ||
53 | } else { | ||
54 | *out = input.substr(0, divider); | ||
55 | out++; | ||
56 | |||
57 | input = input.substr(divider+delimiter.length()); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | template <class Container> | ||
63 | Container split(std::string input, std::string delimiter) | ||
64 | { | ||
65 | Container result; | ||
66 | |||
67 | split(input, delimiter, std::back_inserter(result)); | ||
68 | |||
69 | return result; | ||
70 | } | ||
71 | |||
72 | }; | ||
73 | |||
74 | #endif /* end of include guard: UTIL_H_CED7A66D */ | ||