parses a comma separated list of words after a pattern in one of the arguments in argv
| 6501 | |
| 6502 | // parses a comma separated list of words after a pattern in one of the arguments in argv |
| 6503 | bool parseCommaSepArgs(int argc, const char* const* argv, const char* pattern, |
| 6504 | std::vector<String>& res) { |
| 6505 | String filtersString; |
| 6506 | if(parseOption(argc, argv, pattern, &filtersString)) { |
| 6507 | // tokenize with "," as a separator, unless escaped with backslash |
| 6508 | std::ostringstream s; |
| 6509 | auto flush = [&s, &res]() { |
| 6510 | auto string = s.str(); |
| 6511 | if(string.size() > 0) { |
| 6512 | res.push_back(string.c_str()); |
| 6513 | } |
| 6514 | s.str(""); |
| 6515 | }; |
| 6516 | |
| 6517 | bool seenBackslash = false; |
| 6518 | const char* current = filtersString.c_str(); |
| 6519 | const char* end = current + strlen(current); |
| 6520 | while(current != end) { |
| 6521 | char character = *current++; |
| 6522 | if(seenBackslash) { |
| 6523 | seenBackslash = false; |
| 6524 | if(character == ',' || character == '\\') { |
| 6525 | s.put(character); |
| 6526 | continue; |
| 6527 | } |
| 6528 | s.put('\\'); |
| 6529 | } |
| 6530 | if(character == '\\') { |
| 6531 | seenBackslash = true; |
| 6532 | } else if(character == ',') { |
| 6533 | flush(); |
| 6534 | } else { |
| 6535 | s.put(character); |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | if(seenBackslash) { |
| 6540 | s.put('\\'); |
| 6541 | } |
| 6542 | flush(); |
| 6543 | return true; |
| 6544 | } |
| 6545 | return false; |
| 6546 | } |
| 6547 | |
| 6548 | enum optionType |
| 6549 | { |
no test coverage detected