SlHelpers
Loading...
Searching...
No Matches
Pattern.h
1// SPDX-License-Identifier: GPL-2.0-only
2
3#pragma once
4
5#include <filesystem>
6#include <optional>
7#include <string>
8
9#include "../git/PathSpec.h"
10
11namespace SlKernCVS {
12
16struct Pattern {
17 Pattern() = delete;
18
24 unsigned match(const std::filesystem::path &path) const {
25 if (m_pathspec.matchesPath(path))
26 return m_weight;
27 return 0;
28 }
29
35 static std::optional<Pattern> create(std::string pattern);
36private:
37 SlGit::PathSpec m_pathspec;
38 unsigned m_weight;
39
40 Pattern(SlGit::PathSpec pathspec, unsigned weight) : m_pathspec(std::move(pathspec)),
41 m_weight(weight) {}
42
43 static constexpr unsigned pattern_weight(std::string_view pattern);
44};
45
46}
PathSpec is a representation of git pathspecs.
Definition PathSpec.h:68
static std::optional< Pattern > create(std::string pattern)
Build a (git) Pattern.
unsigned match(const std::filesystem::path &path) const
Match a path against the stored patterns.
Definition Pattern.h:24