diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-12 12:09:58 -0500 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-12 12:09:58 -0500 |
| commit | be9ccb73bc20b03f62c77f5d529602a10ef4eda9 (patch) | |
| tree | 6f88a9b780a75e52b2f04b6f61167f4ef46590a7 /src/util.h | |
| parent | c1a88a064a0cddbc1df2e716ef2102d22bbf681b (diff) | |
| download | ether-be9ccb73bc20b03f62c77f5d529602a10ef4eda9.tar.gz ether-be9ccb73bc20b03f62c77f5d529602a10ef4eda9.tar.bz2 ether-be9ccb73bc20b03f62c77f5d529602a10ef4eda9.zip | |
player has a sprite now thanks to world of solaria
Diffstat (limited to 'src/util.h')
| -rw-r--r-- | src/util.h | 35 |
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 | |||
| 4 | template <typename Container, typename Predicate> | 7 | template <typename Container, typename Predicate> |
| 5 | void erase_if(Container& items, const Predicate& predicate) | 8 | void 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 | ||
| 23 | template <class OutputIterator> | ||
| 24 | void 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 | |||
| 44 | template <class Container> | ||
| 45 | Container 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 */ |
