| 12 | |
| 13 | namespace seissol { |
| 14 | auto IntegerMaskParser::parse(const std::string& maskInput) |
| 15 | -> std::optional<IntegerMaskParser::MaskType> { |
| 16 | MaskType resultMask{}; |
| 17 | |
| 18 | const auto regex = std::regex("^(\\d+|\\d+-\\d+|\\{(\\d+,?)+\\})(,|$)"); |
| 19 | std::smatch match; |
| 20 | |
| 21 | std::string mask = maskInput; |
| 22 | |
| 23 | while (std::regex_search(mask, match, regex)) { |
| 24 | const std::string subString = match[1].str(); |
| 25 | mask = match.suffix(); |
| 26 | |
| 27 | auto intRange = IntegerMaskParser::parseIntRange(subString); |
| 28 | if (intRange) { |
| 29 | resultMask.push_back(*intRange); |
| 30 | continue; |
| 31 | } |
| 32 | |
| 33 | auto intList = IntegerMaskParser::parseIntList(subString); |
| 34 | if (intList) { |
| 35 | resultMask.push_back(*intList); |
| 36 | continue; |
| 37 | } |
| 38 | |
| 39 | resultMask.push_back({std::stoi(subString)}); |
| 40 | } |
| 41 | |
| 42 | if (resultMask.empty()) { |
| 43 | return std::nullopt; |
| 44 | } |
| 45 | return resultMask; |
| 46 | } |
| 47 | |
| 48 | auto IntegerMaskParser::parseIntRange(const std::string& str) |
| 49 | -> IntegerMaskParser::OptionalIntVectorType { |
no test coverage detected