-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[实现 GlobMatch 功能]: 主要实现了 GlobMatch 功能,并对项目文件进行了相应的更新。
- 在项目中添加了 Dependabot 配置文件 `.github/dependabot.yml`,以便自动维护 GitHub Actions 的依赖。 - 更新了 `.github/workflows/build.yml` 文件,移除了不再需要的 `save-always` 配置。 - 在 `CMakeLists.txt` 中添加了 `GlobMatch` 子目录,以支持新功能的构建。 - 添加了 `GlobMatch` 目录和相关文件,包括 `CMakeLists.txt`、`globmatcher.cc`、`globmatcher.hpp` 和 `main.cc`,实现了基于 glob 模式的匹配功能。 - 在 `README.md` 中记录了 `GlobMatch` 功能的添加,并对列表进行了相应的更新。 - 更新了 `vcpkg.json` 文件,以反映项目依赖的变化。
- Loading branch information
Showing
9 changed files
with
131 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "weekly" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_executable(globmatcher_test globmatcher.cc globmatcher.hpp main.cc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "globmatcher.hpp" | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
std::vector<std::string> readGlobPatternsFromFile(const std::string &filename) | ||
{ | ||
std::vector<std::string> patterns; | ||
std::ifstream file(filename); | ||
std::string pattern; | ||
if (file.is_open()) { | ||
while (std::getline(file, pattern)) { | ||
patterns.push_back(pattern); | ||
} | ||
file.close(); | ||
} else { | ||
std::cerr << "Unable to open file: " << filename << std::endl; | ||
} | ||
return patterns; | ||
} | ||
|
||
bool globMatch(const std::string &text, const std::string &pattern) | ||
{ | ||
size_t n = text.size(), m = pattern.size(); | ||
size_t i = 0, j = 0; | ||
while (i < n && j < m) { | ||
if (pattern[j] == '*') { | ||
while (j < m && pattern[j] == '*') | ||
++j; | ||
if (j == m) | ||
return true; | ||
while (i < n && !globMatch(text.substr(i), pattern.substr(j))) { | ||
++i; | ||
} | ||
if (i > 0) | ||
--i; | ||
} else if (pattern[j] == '?' || pattern[j] == text[i]) { | ||
++i; | ||
++j; | ||
} else { | ||
return false; | ||
} | ||
} | ||
while (j < m && pattern[j] == '*') { | ||
++j; | ||
} | ||
return j == m && i == n; | ||
} | ||
|
||
GlobMatcher::GlobMatcher(const std::string &patternFile) | ||
{ | ||
m_patterns = readGlobPatternsFromFile(patternFile); | ||
} | ||
|
||
bool GlobMatcher::match(const std::string &text) | ||
{ | ||
for (const auto &pattern : m_patterns) { | ||
if (globMatch(text, pattern)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <utils/object.hpp> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class GlobMatcher : noncopyable | ||
{ | ||
public: | ||
explicit GlobMatcher(const std::string &patternFile); | ||
|
||
bool match(const std::string &text); | ||
|
||
private: | ||
std::vector<std::string> m_patterns; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "globmatcher.hpp" | ||
|
||
#include <filesystem> | ||
#include <iostream> | ||
|
||
auto main() -> int | ||
{ | ||
auto path = std::filesystem::current_path().parent_path().parent_path(); | ||
std::cout << path << std::endl; | ||
auto filePath = path / ".gitignore"; | ||
|
||
GlobMatcher globMatcher(filePath.string()); | ||
for (const auto &entry : std::filesystem::directory_iterator(path)) { | ||
auto currentPath = entry.path(); | ||
if (globMatcher.match(currentPath.filename().string())) { | ||
std::cout << currentPath << " is ignored by .gitignore" << std::endl; | ||
} else { | ||
std::cout << currentPath << " is not ignored by .gitignore" << std::endl; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters