| 1 |
#include "Glob.hh" |
| 2 |
|
| 3 |
#ifdef __wasm32__ |
| 4 |
extern "C" bool wasm_regex_match(const char *s, const char *regex); |
| 5 |
#endif |
| 6 |
|
| 7 |
Glob::Glob(std::string raw) { |
| 8 |
mRaw = raw; |
| 9 |
mHash = std::hash<std::string>()(raw); |
| 10 |
#ifndef __wasm32__ |
| 11 |
mRegex = std::regex(raw); |
| 12 |
#endif |
| 13 |
} |
| 14 |
|
| 15 |
bool Glob::isIgnored(std::string relative_path) const { |
| 16 |
// Use native JS regex engine for wasm to reduce binary size. |
| 17 |
#ifdef __wasm32__ |
| 18 |
return wasm_regex_match(relative_path.c_str(), mRaw.c_str()); |
| 19 |
#else |
| 20 |
return std::regex_match(relative_path, mRegex); |
| 21 |
#endif |
| 22 |
} |