From da3bc860f66d34f233028e819beee32dd1c43dd8 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 18 Jan 2018 16:49:54 -0500 Subject: Modernized project This rewrite brings the codebase of this project more in line with the format of the other bots, including things like C++ randomization, better abstraction, use of exceptions, etc. Notably, any FFMPEG objects that get allocated are wrapped in simple objects so that they get properly destroyed if an exception is thrown. Some more error detection and cleanliness stuff can probably be done but my wrists really hurt. Also updated librawr, and thus also removed the yaml-cpp submodule. --- util.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 util.h (limited to 'util.h') diff --git a/util.h b/util.h new file mode 100644 index 0000000..c38f624 --- /dev/null +++ b/util.h @@ -0,0 +1,60 @@ +#ifndef UTIL_H_1F6A84F6 +#define UTIL_H_1F6A84F6 + +#include +#include +#include + +template +std::string implode( + InputIterator first, + InputIterator last, + std::string delimiter) +{ + std::stringstream result; + + for (InputIterator it = first; it != last; it++) + { + if (it != first) + { + result << delimiter; + } + + result << *it; + } + + return result.str(); +} + +template +void split(std::string input, std::string delimiter, OutputIterator out) +{ + while (!input.empty()) + { + int divider = input.find(delimiter); + if (divider == std::string::npos) + { + *out = input; + out++; + + input = ""; + } else { + *out = input.substr(0, divider); + out++; + + input = input.substr(divider+delimiter.length()); + } + } +} + +template +Container split(std::string input, std::string delimiter) +{ + Container result; + + split(input, delimiter, std::back_inserter(result)); + + return result; +} + +#endif /* end of include guard: UTIL_H_1F6A84F6 */ -- cgit 1.4.1