Mercurial > hg > vamp-plugin-sdk
comparison src/vamp-hostsdk/Files.cpp @ 474:8e846c1aed96
Merge from branch enumerate-options
| author | Chris Cannam |
|---|---|
| date | Fri, 04 Nov 2016 10:44:27 +0000 |
| parents | 0545cd3f1738 |
| children | 628a5b8ff634 |
comparison
equal
deleted
inserted
replaced
| 472:79a219ba6178 | 474:8e846c1aed96 |
|---|---|
| 64 using namespace std; | 64 using namespace std; |
| 65 | 65 |
| 66 vector<string> | 66 vector<string> |
| 67 Files::listLibraryFiles() | 67 Files::listLibraryFiles() |
| 68 { | 68 { |
| 69 return listLibraryFilesMatching(""); | 69 return listLibraryFilesMatching({}); |
| 70 } | 70 } |
| 71 | 71 |
| 72 vector<string> | 72 vector<string> |
| 73 Files::listLibraryFilesMatching(string libraryName) | 73 Files::listLibraryFilesMatching(Filter filter) |
| 74 { | 74 { |
| 75 vector<string> path = Vamp::PluginHostAdapter::getPluginPath(); | 75 vector<string> path = Vamp::PluginHostAdapter::getPluginPath(); |
| 76 vector<string> libraryFiles; | 76 vector<string> libraryFiles; |
| 77 | 77 |
| 78 // we match case-insensitively, but only with ascii range | 78 // we match case-insensitively, but only with ascii range |
| 79 // characters (this string is expected to be utf-8) | 79 // characters (input strings are expected to be utf-8) |
| 80 for (size_t i = 0; i < libraryName.length(); ++i) { | 80 vector<string> libraryNames; |
| 81 if (!(libraryName[i] & 0x80)) { | 81 for (auto n: filter.libraryNames) { |
| 82 libraryName[i] = char(tolower(libraryName[i])); | 82 for (size_t i = 0; i < n.length(); ++i) { |
| 83 } | 83 if (!(n[i] & 0x80)) { |
| 84 n[i] = char(tolower(n[i])); | |
| 85 } | |
| 86 } | |
| 87 libraryNames.push_back(n); | |
| 84 } | 88 } |
| 85 | 89 |
| 86 for (size_t i = 0; i < path.size(); ++i) { | 90 for (size_t i = 0; i < path.size(); ++i) { |
| 87 | 91 |
| 88 vector<string> files = listFiles(path[i], PLUGIN_SUFFIX); | 92 vector<string> files = listFiles(path[i], PLUGIN_SUFFIX); |
| 89 | 93 |
| 90 for (vector<string>::iterator fi = files.begin(); | 94 for (vector<string>::iterator fi = files.begin(); |
| 91 fi != files.end(); ++fi) { | 95 fi != files.end(); ++fi) { |
| 96 | |
| 97 // we match case-insensitively, but only with ascii range | |
| 98 // characters (this string is expected to be utf-8) | |
| 99 string cleaned = *fi; | |
| 100 for (size_t i = 0; i < cleaned.length(); ++i) { | |
| 101 if (!(cleaned[i] & 0x80)) { | |
| 102 cleaned[i] = char(tolower(cleaned[i])); | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 // libraryName should be lacking an extension, as it is | |
| 107 // supposed to have come from the plugin key | |
| 108 string::size_type pi = cleaned.find('.'); | |
| 109 if (pi != string::npos) { | |
| 110 cleaned = cleaned.substr(0, pi); | |
| 111 } | |
| 92 | 112 |
| 93 if (libraryName != "") { | 113 bool matched = false; |
| 94 // we match case-insensitively, but only with ascii | 114 |
| 95 // range characters (this string is expected to be | 115 switch (filter.type) { |
| 96 // utf-8) | 116 |
| 97 string temp = *fi; | 117 case Filter::All: |
| 98 for (size_t i = 0; i < temp.length(); ++i) { | 118 matched = true; |
| 99 if (!(temp[i] & 0x80)) { | 119 break; |
| 100 temp[i] = char(tolower(temp[i])); | 120 |
| 121 case Filter::Matching: | |
| 122 for (const auto &n: libraryNames) { | |
| 123 if (cleaned == n) { | |
| 124 matched = true; | |
| 125 break; | |
| 101 } | 126 } |
| 102 } | 127 } |
| 103 // libraryName should be lacking an extension, as it | 128 break; |
| 104 // is supposed to have come from the plugin key | 129 |
| 105 string::size_type pi = temp.find('.'); | 130 case Filter::NotMatching: |
| 106 if (pi == string::npos) { | 131 matched = true; |
| 107 if (libraryName != temp) continue; | 132 for (const auto &n: libraryNames) { |
| 108 } else { | 133 if (cleaned == n) { |
| 109 if (libraryName != temp.substr(0, pi)) continue; | 134 matched = false; |
| 135 break; | |
| 136 } | |
| 110 } | 137 } |
| 138 break; | |
| 111 } | 139 } |
| 112 | 140 |
| 141 if (!matched) continue; | |
| 142 | |
| 113 string fullPath = path[i]; | 143 string fullPath = path[i]; |
| 114 fullPath = splicePath(fullPath, *fi); | 144 fullPath = splicePath(fullPath, *fi); |
| 115 libraryFiles.push_back(fullPath); | 145 libraryFiles.push_back(fullPath); |
| 116 } | 146 } |
| 117 } | 147 } |
