diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5d5094d --- /dev/null +++ b/.github/dependabot.yml @@ -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" + \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ded1506..bf79063 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -78,7 +78,6 @@ jobs: ${{ matrix.os }}-vcpkg-installed-${{ runner.os }}- ${{ matrix.os }}-vcpkg-installed- ${{ matrix.os }}- - save-always: true - name: Configure and build windows if: startsWith(matrix.os, 'windows') diff --git a/CMakeLists.txt b/CMakeLists.txt index 3371119..05fd404 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ add_subdirectory(ByteOrder) add_subdirectory(CountDownLatch) add_subdirectory(Crashpad) add_subdirectory(Curl) +add_subdirectory(GlobMatch) add_subdirectory(DesignPattern) add_subdirectory(Glog) add_subdirectory(LinkedList) diff --git a/GlobMatch/CMakeLists.txt b/GlobMatch/CMakeLists.txt new file mode 100644 index 0000000..47d9d24 --- /dev/null +++ b/GlobMatch/CMakeLists.txt @@ -0,0 +1 @@ +add_executable(globmatcher_test globmatcher.cc globmatcher.hpp main.cc) diff --git a/GlobMatch/globmatcher.cc b/GlobMatch/globmatcher.cc new file mode 100644 index 0000000..af977c4 --- /dev/null +++ b/GlobMatch/globmatcher.cc @@ -0,0 +1,63 @@ +#include "globmatcher.hpp" + +#include +#include + +std::vector readGlobPatternsFromFile(const std::string &filename) +{ + std::vector 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; +} diff --git a/GlobMatch/globmatcher.hpp b/GlobMatch/globmatcher.hpp new file mode 100644 index 0000000..d1ea037 --- /dev/null +++ b/GlobMatch/globmatcher.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include + +#include +#include + +class GlobMatcher : noncopyable +{ +public: + explicit GlobMatcher(const std::string &patternFile); + + bool match(const std::string &text); + +private: + std::vector m_patterns; +}; diff --git a/GlobMatch/main.cc b/GlobMatch/main.cc new file mode 100644 index 0000000..8ad3bf1 --- /dev/null +++ b/GlobMatch/main.cc @@ -0,0 +1,23 @@ +#include "globmatcher.hpp" + +#include +#include + +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; +} \ No newline at end of file diff --git a/README.md b/README.md index 19a62e4..58dfc11 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,14 @@ 14. [MVC](/DesignPattern/MVC/model.hpp)——mvc模式; 15. [Observer](/DesignPattern/Observer/observer.hpp)——观察者模式; 16. [Singleton](/DesignPattern/Singleton/singleton.hpp)——单例模式; -17. [Glog](/Glog/main.cc)——google glog的例子; -18. [Icmp](/Icmp/icmp.hpp)——linux icmp协议的简单封装; -19. [LinkedList](/LinkedList/linkedlist.hpp)——链表的相关操作,插入、移除、反转、打印; -20. [Memcpy](/Memcpy/memcpy.hpp)——`memcpy`函数实现; -21. [MonitorDir](/MonitorDir/monitordir.hpp)——windows(`ReadDirectoryChangesW`),macos(`FSEvents`)和linux(`inotify`)目录监控的简单例子; -22. [Mutex](/Mutex/mutex.hpp)——使用std::atomic_flag实现的简单互斥锁和自旋锁; -23. [OpenSSL](/OpenSSL)——openssl的一些例子; +17. [GlobMatch](/GlobMatch/globmatcher.hpp)——glob模式匹配的简单实现; +18. [Glog](/Glog/main.cc)——google glog的例子; +19. [Icmp](/Icmp/icmp.hpp)——linux icmp协议的简单封装; +20. [LinkedList](/LinkedList/linkedlist.hpp)——链表的相关操作,插入、移除、反转、打印; +21. [Memcpy](/Memcpy/memcpy.hpp)——`memcpy`函数实现; +22. [MonitorDir](/MonitorDir/monitordir.hpp)——windows(`ReadDirectoryChangesW`),macos(`FSEvents`)和linux(`inotify`)目录监控的简单例子; +23. [Mutex](/Mutex/mutex.hpp)——使用std::atomic_flag实现的简单互斥锁和自旋锁; +24. [OpenSSL](/OpenSSL)——openssl的一些例子; 1. [aes](/OpenSSL/openssl_aes.cc)——aes加解密的例子; 2. [base64](/OpenSSL/openssl_base64.cc)——base64编解码的例子; 3. [hash](/OpenSSL/openssl_hash.cc)——sha256的例子; @@ -41,10 +42,10 @@ 7. [sm4](/OpenSSL/openssl_sm4.cc)——sm4加解密的例子; 8. [x509](/OpenSSL/openssl_x509.cc)——x509证书的例子; 9. [bash](/OpenSSL/openssl_bash.sh)——openssl命令行的例子; -24. [Server](/Server)——linux server的一些例子; +25. [Server](/Server)——linux server的一些例子; 1. [server_epoll](/Server/server_epoll.cc)——epoll的例子; 2. [server_poll](/Server/server_poll.cc)——poll的例子; 3. [server_select](/Server/server_select.cc)——select的例子; -25. [Thread](/Thread/)——基于std::thread实现的线程类,包括线程池; +26. [Thread](/Thread/)——基于std::thread实现的线程类,包括线程池; 1. [Thread](/Thread/thread.hpp)——线程类; 2. [ThreadPool](/Thread/threadpool.hpp)——线程池; diff --git a/vcpkg.json b/vcpkg.json index a476d25..5931ace 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,6 +8,7 @@ "breakpad", "benchmark", "gtest", + "crashpad", { "name": "openssl", "features": [ @@ -23,8 +24,7 @@ "http2", "tool" ] - }, - "crashpad" + } ], - "builtin-baseline": "8150939b69720adc475461978e07c2d2bf5fb76e" -} \ No newline at end of file + "builtin-baseline": "5f4628b89f3f98cd9a0b43c27ded2aa53da1f790" +}