Skip to content

Commit

Permalink
Shange occurrences of std::regex uses to RE2 library calls in glob li…
Browse files Browse the repository at this point in the history
…brary (#4100)
  • Loading branch information
mxwli authored Aug 19, 2024
1 parent dac484c commit 87de7f9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi
12 changes: 12 additions & 0 deletions test/test_files/glob/longpath.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-DATASET CSV empty

--

-CASE LongPath
-STATEMENT CREATE NODE TABLE tab(msg string, primary key(msg));
---- ok
-STATEMENT COPY tab FROM '${KUZU_ROOT_DIRECTORY}/dataset/copy-fault-tests/*/nested/*/path/test/with-a-reallllllllllllllllllllly-long-name/big-comma-separated-values-*-name-with-long-path.csv' (HEADER=FALSE);
---- ok
-STATEMENT MATCH (t:tab) RETURN t.*;
---- 1
hi
26 changes: 13 additions & 13 deletions third_party/glob/glob/glob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include <filesystem>
#endif

#include "re2.h"

namespace glob {

#ifdef GLOB_USE_GHC_FILESYSTEM
Expand Down Expand Up @@ -128,10 +130,12 @@ std::string translate(const std::string &pattern) {

// Escape set operations (&&, ~~ and ||).
std::string result;
std::regex_replace(std::back_inserter(result), // result
stuff.begin(), stuff.end(), // string
std::regex(std::string{R"([&~|])"}), // pattern
std::string{R"(\\\1)"}); // repl
for (const auto& i: stuff) {
if (i == '&' || i == '~' || i == '|') {
result.push_back('\\');
}
result.push_back(i);
}
stuff = result;
i = j + 1;
if (stuff[0] == '!') {
Expand Down Expand Up @@ -166,14 +170,9 @@ std::string translate(const std::string &pattern) {
return std::string{"(("} + result_string + std::string{R"()|[\r\n])$)"};
}

static inline
std::regex compile_pattern(const std::string &pattern) {
return std::regex(translate(pattern), std::regex::ECMAScript);
}

static inline
bool fnmatch(const fs::path &name, const std::string &pattern) {
return std::regex_match(name.string(), compile_pattern(pattern));
return RE2::FullMatch(name.string(), translate(pattern));
}

static inline
Expand Down Expand Up @@ -215,13 +214,14 @@ fs::path expand_tilde(fs::path path) {

static inline
bool has_magic(const std::string &pathname) {
static const auto magic_check = std::regex("([*?[])");
return std::regex_search(pathname, magic_check);
static const auto magic_check = RE2("([*?[])");
return RE2::PartialMatch(pathname, magic_check);
}

static inline
bool is_hidden(const std::string &pathname) {
return std::regex_match(pathname, std::regex("^(.*\\/)*\\.[^\\.\\/]+\\/*$"));
static const auto check = RE2("^(.*\\/)*\\.[^\\.\\/]+\\/*$");
return RE2::FullMatch(pathname, check);
}

static inline
Expand Down

0 comments on commit 87de7f9

Please sign in to comment.