using namespace std;
using namespace PBD;
+static
+bool
+regexp_filter (const string& str, void *arg)
+{
+ regex_t* pattern = (regex_t*)arg;
+ return regexec (pattern, str.c_str(), 0, 0, 0) == 0;
+}
+
vector<string>
PathScanner::operator() (const string &dirpath, const string ®exp,
bool match_fullpath, bool return_fullpath,
{
int err;
char msg[256];
+ regex_t compiled_pattern;
+ vector<string> result;
if ((err = regcomp (&compiled_pattern, regexp.c_str(),
REG_EXTENDED|REG_NOSUB))) {
return vector<string>();
}
- return run_scan (dirpath, &PathScanner::regexp_filter,
- (bool (*)(const string &, void *)) 0,
- 0,
- match_fullpath,
- return_fullpath,
- limit, recurse);
+ result = run_scan (dirpath,
+ regexp_filter,
+ &compiled_pattern,
+ match_fullpath,
+ return_fullpath,
+ limit, recurse);
+
+ regfree (&compiled_pattern);
+
+ return result;
}
vector<string>
PathScanner::run_scan (const string &dirpath,
- bool (PathScanner::*memberfilter)(const string &),
bool (*filter)(const string &, void *),
void *arg,
bool match_fullpath, bool return_fullpath,
bool recurse)
{
vector<string> result;
- run_scan_internal (result, dirpath, memberfilter, filter, arg, match_fullpath, return_fullpath, limit, recurse);
+ run_scan_internal (result, dirpath, filter, arg, match_fullpath, return_fullpath, limit, recurse);
return result;
}
void
PathScanner::run_scan_internal (vector<string>& result,
const string &dirpath,
- bool (PathScanner::*memberfilter)(const string &),
bool (*filter)(const string &, void *),
void *arg,
bool match_fullpath, bool return_fullpath,
}
if (statbuf.st_mode & S_IFDIR && recurse) {
- run_scan_internal (result, fullpath, memberfilter, filter, arg, match_fullpath, return_fullpath, limit, recurse);
+ run_scan_internal (result, fullpath, filter, arg, match_fullpath, return_fullpath, limit, recurse);
} else {
if (match_fullpath) {
search_str = finfo->d_name;
}
- /* handle either type of function ptr */
-
- if (memberfilter) {
- if (!(this->*memberfilter)(search_str)) {
- continue;
- }
- } else {
- if (!filter(search_str, arg)) {
- continue;
- }
+ if (!filter(search_str, arg)) {
+ continue;
}
if (return_fullpath) {
vector<string> res;
int err;
char msg[256];
+ regex_t compiled_pattern;
if ((err = regcomp (&compiled_pattern, regexp.c_str(),
REG_EXTENDED|REG_NOSUB))) {
}
run_scan_internal (res, dirpath,
- &PathScanner::regexp_filter,
- (bool (*)(const string &, void *)) 0,
- 0,
+ ®exp_filter,
+ &compiled_pattern,
match_fullpath,
return_fullpath,
1);
+ regfree (&compiled_pattern);
+
if (res.size() == 0) {
return string();
}
run_scan_internal (res,
dirpath,
- (bool (PathScanner::*)(const string &)) 0,
filter,
0,
match_fullpath,
long limit = -1,
bool recurse = false) {
return run_scan (dirpath,
- (bool (PathScanner::*)(const std::string &)) 0,
filter,
arg,
match_fullpath,
bool return_fullpath = true);
private:
- regex_t compiled_pattern;
-
- bool regexp_filter (const std::string &str) {
- return regexec (&compiled_pattern, str.c_str(), 0, 0, 0) == 0;
- }
-
+
std::vector<std::string> run_scan (const std::string &dirpath,
- bool (PathScanner::*mfilter) (const std::string &),
bool (*filter)(const std::string &, void *),
void *arg,
bool match_fullpath,
void run_scan_internal (std::vector<std::string>&,
const std::string &dirpath,
- bool (PathScanner::*mfilter) (const std::string &),
bool (*filter)(const std::string &, void *),
void *arg,
bool match_fullpath,