diff options
Diffstat (limited to 'src/tracking')
-rw-r--r-- | src/tracking/change_tracker.cc | 2 | ||||
-rw-r--r-- | src/tracking/path_matcher.cc | 39 | ||||
-rw-r--r-- | src/tracking/path_matcher.h | 22 |
3 files changed, 62 insertions, 1 deletions
diff --git a/src/tracking/change_tracker.cc b/src/tracking/change_tracker.cc index df91be0..9eab5a2 100644 --- a/src/tracking/change_tracker.cc +++ b/src/tracking/change_tracker.cc @@ -125,7 +125,7 @@ void ChangeTracker::track(const std::string& file_path) { if ( std::get<EMPLACE_SUCCESS>(result) ) { read_file_to_stream( - full_path, + full_path, std::get<FILE_CONTENT>(*result.first).get() ); } diff --git a/src/tracking/path_matcher.cc b/src/tracking/path_matcher.cc new file mode 100644 index 0000000..e754586 --- /dev/null +++ b/src/tracking/path_matcher.cc @@ -0,0 +1,39 @@ +#include "path_matcher.h" + +#include <algorithm> + +#include <boost/filesystem.hpp> +#include <boost/filesystem/fstream.hpp> + +namespace tracking { + +PathMatcher::PathMatcher(const std::string& source_file_path) { + try { + boost::filesystem::ifstream file(source_file_path); + + if ( file.is_open() ) { + std::string current_line; + + while ( std::getline(file, current_line) ) { + try { + this->patterns_.emplace_back(current_line); + } catch ( const std::regex_error& ) { } + } + } + } catch ( boost::filesystem::filesystem_error& ) { + // invalid source path is not relevant as we can easily fall back to declining + // all candidate paths. + } +} + +bool PathMatcher::isMatching(const std::string& candidate) const { + return std::any_of( + this->patterns_.begin(), + this->patterns_.end(), + [&candidate](const std::regex& pattern) -> bool { + return std::regex_match(candidate, pattern); + } + ); +} + +} diff --git a/src/tracking/path_matcher.h b/src/tracking/path_matcher.h new file mode 100644 index 0000000..64337c0 --- /dev/null +++ b/src/tracking/path_matcher.h @@ -0,0 +1,22 @@ +#ifndef CHANGE_SRC_TRACKING_PATH_MATCHER_H_ +#define CHANGE_SRC_TRACKING_PATH_MATCHER_H_ + +#include <regex> +#include <vector> + +namespace tracking { + +class PathMatcher { + public: + PathMatcher() = default; + PathMatcher(const std::string&); + + bool isMatching(const std::string&) const; + + private: + std::vector<std::regex> patterns_; +}; + +} + +#endif // CHANGE_SRC_TRACKING_PATH_MATCHER_H_ |