-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
28 lines (22 loc) · 844 Bytes
/
utils.h
File metadata and controls
28 lines (22 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once
#include <algorithm>
#include <string>
#include <regex>
namespace libtouchstone {
// Check if a container contains a value.
template<typename Container, typename T>
inline bool contains(const Container& container, const T& value) {
return std::find(container.begin(), container.end(), value) != container.end();
}
// String-specific overload for substring search.
inline bool contains(const std::string& str, const char* substr) {
return str.find(substr) != std::string::npos;
}
// Extract a group from a regex match.
inline std::string regex_extract(const std::string& str, const std::string& pattern, int group = 1) {
std::regex re(pattern);
std::smatch match;
if (std::regex_search(str, match, re) && (int)match.size() > group) return match[group].str();
return "";
}
} // namespace libtouchstone