MCPcopy Create free account
hub / github.com/apache/arrow / PatternToRegex

Method PatternToRegex

cpp/src/arrow/filesystem/path_util.cc:365–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363 explicit Impl(const std::string& p) : pattern_(std::regex(PatternToRegex(p))) {}
364
365 static std::string PatternToRegex(const std::string& p) {
366 std::string special_chars = "()[]{}+-|^$\\.&~# \t\n\r\v\f";
367 std::string transformed;
368 auto it = p.begin();
369 while (it != p.end()) {
370 if (*it == '\\') {
371 transformed += '\\';
372 if (++it != p.end()) {
373 transformed += *it;
374 }
375 } else if (*it == '*') {
376 transformed += "[^/]*";
377 } else if (*it == '?') {
378 transformed += "[^/]";
379 } else if (special_chars.find(*it) != std::string::npos) {
380 transformed += "\\";
381 transformed += *it;
382 } else {
383 transformed += *it;
384 }
385 it++;
386 }
387 return transformed;
388 }
389};
390
391Globber::Globber(std::string pattern) : impl_(new Impl(pattern)) {}

Callers

nothing calls this directly

Calls 3

beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected