diff options
Diffstat (limited to 'lib/util.h')
| -rw-r--r-- | lib/util.h | 22 |
1 files changed, 11 insertions, 11 deletions
| diff --git a/lib/util.h b/lib/util.h index b74b050..9db8678 100644 --- a/lib/util.h +++ b/lib/util.h | |||
| @@ -6,25 +6,25 @@ | |||
| 6 | #include <iterator> | 6 | #include <iterator> |
| 7 | 7 | ||
| 8 | namespace verbly { | 8 | namespace verbly { |
| 9 | 9 | ||
| 10 | template <class InputIterator> | 10 | template <class InputIterator> |
| 11 | std::string implode(InputIterator first, InputIterator last, std::string delimiter) | 11 | std::string implode(InputIterator first, InputIterator last, std::string delimiter) |
| 12 | { | 12 | { |
| 13 | std::stringstream result; | 13 | std::stringstream result; |
| 14 | 14 | ||
| 15 | for (InputIterator it = first; it != last; it++) | 15 | for (InputIterator it = first; it != last; it++) |
| 16 | { | 16 | { |
| 17 | if (it != first) | 17 | if (it != first) |
| 18 | { | 18 | { |
| 19 | result << delimiter; | 19 | result << delimiter; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | result << *it; | 22 | result << *it; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | return result.str(); | 25 | return result.str(); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | template <class OutputIterator> | 28 | template <class OutputIterator> |
| 29 | void split(std::string input, std::string delimiter, OutputIterator out) | 29 | void split(std::string input, std::string delimiter, OutputIterator out) |
| 30 | { | 30 | { |
| @@ -35,27 +35,27 @@ namespace verbly { | |||
| 35 | { | 35 | { |
| 36 | *out = input; | 36 | *out = input; |
| 37 | out++; | 37 | out++; |
| 38 | 38 | ||
| 39 | input = ""; | 39 | input = ""; |
| 40 | } else { | 40 | } else { |
| 41 | *out = input.substr(0, divider); | 41 | *out = input.substr(0, divider); |
| 42 | out++; | 42 | out++; |
| 43 | 43 | ||
| 44 | input = input.substr(divider+delimiter.length()); | 44 | input = input.substr(divider+delimiter.length()); |
| 45 | } | 45 | } |
| 46 | } | 46 | } |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | template <class Container> | 49 | template <class Container> |
| 50 | Container split(std::string input, std::string delimiter) | 50 | Container split(std::string input, std::string delimiter) |
| 51 | { | 51 | { |
| 52 | Container result; | 52 | Container result; |
| 53 | 53 | ||
| 54 | split(input, delimiter, std::back_inserter(result)); | 54 | split(input, delimiter, std::back_inserter(result)); |
| 55 | 55 | ||
| 56 | return result; | 56 | return result; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | }; | 59 | }; |
| 60 | 60 | ||
| 61 | #endif /* end of include guard: UTIL_H_15DDCA2D */ | 61 | #endif /* end of include guard: UTIL_H_15DDCA2D */ |
