summary refs log tree commit diff stats
path: root/util.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-01-18 16:49:54 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-01-18 16:49:54 -0500
commitda3bc860f66d34f233028e819beee32dd1c43dd8 (patch)
tree8cc7f5ad0a8dad69ea5c3ae0405f803d3ba80051 /util.h
parent46db0368fbee4cfba97178837e62f4469c4fa884 (diff)
downloadsap-da3bc860f66d34f233028e819beee32dd1c43dd8.tar.gz
sap-da3bc860f66d34f233028e819beee32dd1c43dd8.tar.bz2
sap-da3bc860f66d34f233028e819beee32dd1c43dd8.zip
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.
Diffstat (limited to 'util.h')
-rw-r--r--util.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/util.h b/util.h new file mode 100644 index 0000000..c38f624 --- /dev/null +++ b/util.h
@@ -0,0 +1,60 @@
1#ifndef UTIL_H_1F6A84F6
2#define UTIL_H_1F6A84F6
3
4#include <string>
5#include <sstream>
6#include <iterator>
7
8template <class InputIterator>
9std::string implode(
10 InputIterator first,
11 InputIterator last,
12 std::string delimiter)
13{
14 std::stringstream result;
15
16 for (InputIterator it = first; it != last; it++)
17 {
18 if (it != first)
19 {
20 result << delimiter;
21 }
22
23 result << *it;
24 }
25
26 return result.str();
27}
28
29template <class OutputIterator>
30void split(std::string input, std::string delimiter, OutputIterator out)
31{
32 while (!input.empty())
33 {
34 int divider = input.find(delimiter);
35 if (divider == std::string::npos)
36 {
37 *out = input;
38 out++;
39
40 input = "";
41 } else {
42 *out = input.substr(0, divider);
43 out++;
44
45 input = input.substr(divider+delimiter.length());
46 }
47 }
48}
49
50template <class Container>
51Container split(std::string input, std::string delimiter)
52{
53 Container result;
54
55 split(input, delimiter, std::back_inserter(result));
56
57 return result;
58}
59
60#endif /* end of include guard: UTIL_H_1F6A84F6 */