From c0477410ec65ca988963ba9c0659b60523872de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dinel?= Date: Tue, 9 Mar 2021 11:38:36 -0500 Subject: [PATCH 1/2] Parent directory ( ../ ) and current directory ( ./ ) should not be considered hidden --- single_include/glob/glob.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/single_include/glob/glob.hpp b/single_include/glob/glob.hpp index 32cadcd..b568c47 100644 --- a/single_include/glob/glob.hpp +++ b/single_include/glob/glob.hpp @@ -181,7 +181,12 @@ bool has_magic(const std::string &pathname) { } static inline -bool is_hidden(const std::string &pathname) { return pathname[0] == '.'; } +bool is_hidden(const std::string &pathname) { + // path is hidden if it starts with dot and is not parent dir nor current dir + if (pathname.size() >= 2) + return pathname.at(0) == '.' && pathname.at(1) != '.' && pathname.at(1) != '/'; + return pathname[0] == '.'; +} static inline bool is_recursive(const std::string &pattern) { return pattern == "**"; } From c6f15230ae8832df1073490e3d62a07a15efb87d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dinel?= Date: Tue, 16 Mar 2021 14:34:52 -0400 Subject: [PATCH 2/2] Improve is_hidden --- single_include/glob/glob.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/single_include/glob/glob.hpp b/single_include/glob/glob.hpp index b568c47..d2447fd 100644 --- a/single_include/glob/glob.hpp +++ b/single_include/glob/glob.hpp @@ -182,10 +182,7 @@ bool has_magic(const std::string &pathname) { static inline bool is_hidden(const std::string &pathname) { - // path is hidden if it starts with dot and is not parent dir nor current dir - if (pathname.size() >= 2) - return pathname.at(0) == '.' && pathname.at(1) != '.' && pathname.at(1) != '/'; - return pathname[0] == '.'; + return std::regex_match(pathname, std::regex("^(.*\\/)*\\.[^\\.\\/]+\\/*$")); } static inline