VAPOR3 3.9.4
STLUtils.h
Go to the documentation of this file.
1#pragma once
2
3#include <vapor/MyBase.h>
4#include <string>
5#include <vector>
6#include <algorithm>
7#include <functional>
8#include <iterator>
9
10namespace STLUtils {
11
12template<typename T> bool Contains(const std::vector<T> &toSearch, const T &object) { return std::find(toSearch.cbegin(), toSearch.cend(), object) != toSearch.cend(); }
13
14template<typename T> void AppendTo(std::vector<T> &a, const std::vector<T> &b) { a.insert(a.end(), b.begin(), b.end()); }
15
16template<typename T> std::vector<T> Slice(const std::vector<T> &a, int from, int to = -1) { return std::vector<T>(a.begin() + from, to < 0 ? a.end() : a.begin() + to); }
17
18template<typename T> vector<T> Filter(const std::vector<T> &v, std::function<bool(const T&)> f) {
19 vector<T> v2;
20 std::copy_if(v.begin(), v.end(), std::back_inserter(v2), f);
21 return v2;
22}
23
24template<typename T> bool BeginsWith(const T &str, const T &match) {
25 return str.size() >= match.size() && equal(match.begin(), match.end(), str.begin());
26}
27COMMON_API bool BeginsWith(const std::string &str, const std::string &match);
28
29COMMON_API bool Contains(const std::string &toSearch, const std::string &query);
30COMMON_API bool ContainsIgnoreCase(const std::string &toSearch, const std::string &query);
31COMMON_API bool EndsWith(const std::string &str, const std::string &match);
32COMMON_API std::string ToLower(std::string str);
33COMMON_API std::vector<std::string> Split(std::string str, const std::string &delimeter);
34COMMON_API std::string Join(const std::vector<std::string> &parts, const std::string &delimeter);
35COMMON_API std::string ReplaceAll(std::string source, const std::string &oldSegment, const std::string &newSegment);
36
37} // namespace STLUtils
#define COMMON_API
Definition: common.h:72
COMMON_API bool ContainsIgnoreCase(const std::string &toSearch, const std::string &query)
vector< T > Filter(const std::vector< T > &v, std::function< bool(const T &)> f)
Definition: STLUtils.h:18
COMMON_API std::string ReplaceAll(std::string source, const std::string &oldSegment, const std::string &newSegment)
std::vector< T > Slice(const std::vector< T > &a, int from, int to=-1)
Definition: STLUtils.h:16
COMMON_API std::string ToLower(std::string str)
bool BeginsWith(const T &str, const T &match)
Definition: STLUtils.h:24
COMMON_API std::string Join(const std::vector< std::string > &parts, const std::string &delimeter)
bool Contains(const std::vector< T > &toSearch, const T &object)
Definition: STLUtils.h:12
COMMON_API std::vector< std::string > Split(std::string str, const std::string &delimeter)
void AppendTo(std::vector< T > &a, const std::vector< T > &b)
Definition: STLUtils.h:14
COMMON_API bool EndsWith(const std::string &str, const std::string &match)