summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2014-06-17 11:15:10 +1000
committerTim Mayberry <mojofunk@gmail.com>2014-06-17 21:13:32 +1000
commitf54092dadac9e177e925f3c59cf033a7b1b4c9ce (patch)
treef21f19dc46d27f31b1dba34d4c3604421feba139
parentf220d011320528ab08bee25d9ce790bcd0c637f2 (diff)
Add PathScanner::find_files_matching_regex and move regexp usage to one place
-rw-r--r--libs/pbd/pathscanner.cc69
-rw-r--r--libs/pbd/pbd/pathscanner.h8
2 files changed, 41 insertions, 36 deletions
diff --git a/libs/pbd/pathscanner.cc b/libs/pbd/pathscanner.cc
index 05e90b599b..1a197b27aa 100644
--- a/libs/pbd/pathscanner.cc
+++ b/libs/pbd/pathscanner.cc
@@ -52,16 +52,17 @@ regexp_filter (const string& str, void *arg)
return regexec (pattern, str.c_str(), 0, 0, 0) == 0;
}
-vector<string>
-PathScanner::operator() (const string &dirpath, const string &regexp,
- bool match_fullpath, bool return_fullpath,
- long limit, bool recurse)
-
+void
+PathScanner::find_files_matching_regex (vector<string>& result,
+ const std::string& dirpath,
+ const std::string& regexp,
+ bool match_fullpath, bool return_fullpath,
+ long limit,
+ bool recurse)
{
int err;
char msg[256];
regex_t compiled_pattern;
- vector<string> result;
if ((err = regcomp (&compiled_pattern, regexp.c_str(),
REG_EXTENDED|REG_NOSUB))) {
@@ -74,17 +75,33 @@ PathScanner::operator() (const string &dirpath, const string &regexp,
<< ")"
<< endmsg;
- return vector<string>();
+ return;
}
-
- result = run_scan (dirpath,
- regexp_filter,
- &compiled_pattern,
- match_fullpath,
- return_fullpath,
- limit, recurse);
+
+ result = run_scan (dirpath,
+ regexp_filter,
+ &compiled_pattern,
+ match_fullpath,
+ return_fullpath,
+ limit, recurse);
regfree (&compiled_pattern);
+}
+
+vector<string>
+PathScanner::operator() (const string &dirpath, const string &regexp,
+ bool match_fullpath, bool return_fullpath,
+ long limit, bool recurse)
+
+{
+ vector<string> result;
+
+ find_files_matching_regex (result,
+ dirpath,
+ regexp,
+ match_fullpath,
+ return_fullpath,
+ limit, recurse);
return result;
}
@@ -184,30 +201,10 @@ PathScanner::find_first (const string &dirpath,
bool 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))) {
-
- regerror (err, &compiled_pattern,
- msg, sizeof (msg));
-
- error << "Cannot compile soundfile regexp for use (" << msg << ")" << endmsg;
- return 0;
- }
+ find_files_matching_regex (res, dirpath, regexp,
+ match_fullpath, return_fullpath, 1);
- run_scan_internal (res, dirpath,
- &regexp_filter,
- &compiled_pattern,
- match_fullpath,
- return_fullpath,
- 1);
-
- regfree (&compiled_pattern);
-
if (res.size() == 0) {
return string();
}
diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h
index de23d7c645..4d9ef56e15 100644
--- a/libs/pbd/pbd/pathscanner.h
+++ b/libs/pbd/pbd/pathscanner.h
@@ -69,6 +69,14 @@ class LIBPBD_API PathScanner
private:
+ void find_files_matching_regex (std::vector<std::string>& results,
+ const std::string& dirpath,
+ const std::string& regexp,
+ bool match_fullpath,
+ bool return_fullpath,
+ long limit,
+ bool recurse = false);
+
std::vector<std::string> run_scan (const std::string &dirpath,
bool (*filter)(const std::string &, void *),
void *arg,