| 1349 | } |
| 1350 | |
| 1351 | void IGFD::FilterManager::ParseFilters(const char* vFilters) { |
| 1352 | m_ParsedFilters.clear(); |
| 1353 | |
| 1354 | if (vFilters) { |
| 1355 | dLGFilters = vFilters; // file mode |
| 1356 | } else { |
| 1357 | dLGFilters.clear(); // directory mode |
| 1358 | } |
| 1359 | |
| 1360 | if (!dLGFilters.empty()) { |
| 1361 | /* Rules |
| 1362 | 0) a filter must have 2 chars mini and the first must be a . |
| 1363 | 1) a regex must be in (( and )) |
| 1364 | 2) a , will separate filters except if between a ( and ) |
| 1365 | 3) name{filter1, filter2} is a spetial form for collection filters |
| 1366 | 3.1) the name can be composed of what you want except { and } |
| 1367 | 3.2) the filter can be a regex |
| 1368 | 4) the filters cannot integrate these chars '(' ')' '{' '}' ' ' except for a regex with respect to rule 1) |
| 1369 | 5) the filters cannot integrate a ',' |
| 1370 | */ |
| 1371 | |
| 1372 | bool current_filter_found = false; |
| 1373 | bool started = false; |
| 1374 | bool regex_started = false; |
| 1375 | bool parenthesis_started = false; |
| 1376 | |
| 1377 | std::string word; |
| 1378 | std::string filter_name; |
| 1379 | |
| 1380 | char last_char = 0; |
| 1381 | for (char c : dLGFilters) { |
| 1382 | if (c == '{') { |
| 1383 | if (regex_started) { |
| 1384 | word += c; |
| 1385 | } else { |
| 1386 | started = true; |
| 1387 | m_ParsedFilters.emplace_back(); |
| 1388 | m_ParsedFilters.back().setCollectionTitle(filter_name); |
| 1389 | filter_name.clear(); |
| 1390 | word.clear(); |
| 1391 | } |
| 1392 | } else if (c == '}') { |
| 1393 | if (regex_started) { |
| 1394 | word += c; |
| 1395 | } else { |
| 1396 | if (started) { |
| 1397 | if (word.size() > 1U && word[0] == '.') { |
| 1398 | if (m_ParsedFilters.empty()) { |
| 1399 | m_ParsedFilters.emplace_back(); |
| 1400 | } |
| 1401 | m_ParsedFilters.back().addCollectionFilter(word, false); |
| 1402 | } |
| 1403 | word.clear(); |
| 1404 | filter_name.clear(); |
| 1405 | started = false; |
| 1406 | } |
| 1407 | } |
| 1408 | } else if (c == '(') { |
no test coverage detected