diff options
Diffstat (limited to 'lib/util.h')
-rw-r--r-- | lib/util.h | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/util.h b/lib/util.h index fb5fe67..b74b050 100644 --- a/lib/util.h +++ b/lib/util.h | |||
@@ -1,6 +1,10 @@ | |||
1 | #ifndef UTIL_H_15DDCA2D | 1 | #ifndef UTIL_H_15DDCA2D |
2 | #define UTIL_H_15DDCA2D | 2 | #define UTIL_H_15DDCA2D |
3 | 3 | ||
4 | #include <string> | ||
5 | #include <sstream> | ||
6 | #include <iterator> | ||
7 | |||
4 | namespace verbly { | 8 | namespace verbly { |
5 | 9 | ||
6 | template <class InputIterator> | 10 | template <class InputIterator> |
@@ -21,25 +25,33 @@ namespace verbly { | |||
21 | return result.str(); | 25 | return result.str(); |
22 | } | 26 | } |
23 | 27 | ||
24 | template <class Container> | 28 | template <class OutputIterator> |
25 | Container split(std::string input, std::string delimiter) | 29 | void split(std::string input, std::string delimiter, OutputIterator out) |
26 | { | 30 | { |
27 | Container result; | ||
28 | |||
29 | while (!input.empty()) | 31 | while (!input.empty()) |
30 | { | 32 | { |
31 | int divider = input.find(delimiter); | 33 | int divider = input.find(delimiter); |
32 | if (divider == std::string::npos) | 34 | if (divider == std::string::npos) |
33 | { | 35 | { |
34 | result.push_back(input); | 36 | *out = input; |
37 | out++; | ||
35 | 38 | ||
36 | input = ""; | 39 | input = ""; |
37 | } else { | 40 | } else { |
38 | result.push_back(input.substr(0, divider)); | 41 | *out = input.substr(0, divider); |
42 | out++; | ||
39 | 43 | ||
40 | input = input.substr(divider+delimiter.length()); | 44 | input = input.substr(divider+delimiter.length()); |
41 | } | 45 | } |
42 | } | 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)); | ||
43 | 55 | ||
44 | return result; | 56 | return result; |
45 | } | 57 | } |