summary refs log tree commit diff stats
path: root/src/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h index 150a6a5..1eb2303 100644 --- a/src/util.h +++ b/src/util.h
@@ -1,6 +1,9 @@
1#ifndef UTIL_H_E9110D4C 1#ifndef UTIL_H_E9110D4C
2#define UTIL_H_E9110D4C 2#define UTIL_H_E9110D4C
3 3
4#include <string>
5#include <iterator>
6
4template <typename Container, typename Predicate> 7template <typename Container, typename Predicate>
5void erase_if(Container& items, const Predicate& predicate) 8void erase_if(Container& items, const Predicate& predicate)
6{ 9{
@@ -17,4 +20,36 @@ void erase_if(Container& items, const Predicate& predicate)
17 } 20 }
18}; 21};
19 22
23template <class OutputIterator>
24void splitStr(
25 std::string input,
26 std::string delimiter,
27 OutputIterator out) {
28 while (!input.empty()) {
29 int divider = input.find(delimiter);
30 if (divider == std::string::npos) {
31 *out = input;
32 out++;
33
34 input = "";
35 } else {
36 *out = input.substr(0, divider);
37 out++;
38
39 input = input.substr(divider+delimiter.length());
40 }
41 }
42}
43
44template <class Container>
45Container splitStr(
46 std::string input,
47 std::string delimiter) {
48 Container result;
49
50 splitStr(input, delimiter, std::back_inserter(result));
51
52 return result;
53}
54
20#endif /* end of include guard: UTIL_H_E9110D4C */ 55#endif /* end of include guard: UTIL_H_E9110D4C */