From ee3505090df59bdd7ddaa5469ed5592323577f79 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 22 Nov 2021 11:27:48 +0100 Subject: [PATCH] Added helper-file for finding items in std::vector --- helper/find.hpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 helper/find.hpp diff --git a/helper/find.hpp b/helper/find.hpp new file mode 100644 index 0000000..2a1c6cb --- /dev/null +++ b/helper/find.hpp @@ -0,0 +1,38 @@ +#ifndef B6A9DEE0_30C6_4492_AB96_87D9C5C10E8B +#define B6A9DEE0_30C6_4492_AB96_87D9C5C10E8B + +#include +#include + +void prepare(const int &size, int &start, const int &offset, int &end){ + // Set missing fields + if(!end) end = size; + + // Edit start/end according to offset + if(offset < 0) + start += offset; + else if(offset > 0) + end -= offset; +} + +int findContains(const std::vector &data, const std::string &strContains, int start = 0, int offset = 0, int end = 0){ + prepare(data.size(), start, offset, end); + + for(int i=start; i &data, const std::string &strIs, int start = 0, int offset = 0, int end = 0){ + prepare(data.size(), start, offset, end); + + for(int i=start; i