-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathmatcher.hpp
More file actions
49 lines (41 loc) · 1.68 KB
/
matcher.hpp
File metadata and controls
49 lines (41 loc) · 1.68 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "string_view.hpp"
#include <vector>
#include <regex>
#include <memory>
namespace sdptransform
{
namespace matcher
{
class Interface {
public:
virtual bool doMatch(const std::string& content) const = 0;
using Results=std::vector<string_view>;
virtual Results getMatches(const std::string& content) const = 0;
};
using Ptr=std::shared_ptr<Interface>;
class Regex final : public Interface {
public:
Regex(std::string&& regex) : regex_(std::move(regex)) {}
Regex(const char* prefix, std::string&& regex) : regex_(std::move(regex)), prefix_(prefix) {}
bool doMatch(const std::string& content) const override;
Results getMatches(const std::string& content) const override;
private:
std::pair<std::string::const_iterator,std::string::const_iterator> getIteratorAfterPrefixMatch(const std::string& content) const;
std::regex regex_;
std::string prefix_={};
};
template<typename... T>
inline std::shared_ptr<Regex> createRegex(T&&... vals) {
return std::make_shared<Regex>(std::forward<T>(vals)...);
}
class WholeMatcher final : public Interface {
public:
bool doMatch(const std::string&) const override { return true; }
Results getMatches(const std::string& content) const override { return {string_view(content)}; }
};
inline std::shared_ptr<WholeMatcher> createWholeMatcher() {
return std::make_shared<WholeMatcher>();
}
} // namespace matcher
} // namespace sdptransform