| 5716 | } |
| 5717 | |
| 5718 | Optional<ReporterSpec> parseReporterSpec( StringRef reporterSpec ) { |
| 5719 | auto parts = Detail::splitReporterSpec( reporterSpec ); |
| 5720 | |
| 5721 | assert( parts.size() > 0 && "Split should never return empty vector" ); |
| 5722 | |
| 5723 | std::map<std::string, std::string> kvPairs; |
| 5724 | Optional<std::string> outputFileName; |
| 5725 | Optional<ColourMode> colourMode; |
| 5726 | |
| 5727 | // First part is always reporter name, so we skip it |
| 5728 | for ( size_t i = 1; i < parts.size(); ++i ) { |
| 5729 | auto kv = splitKVPair( parts[i] ); |
| 5730 | auto key = kv.key, value = kv.value; |
| 5731 | |
| 5732 | if ( key.empty() || value.empty() ) { // NOLINT(bugprone-branch-clone) |
| 5733 | return {}; |
| 5734 | } else if ( key[0] == 'X' ) { |
| 5735 | // This is a reporter-specific option, we don't check these |
| 5736 | // apart from basic sanity checks |
| 5737 | if ( key.size() == 1 ) { |
| 5738 | return {}; |
| 5739 | } |
| 5740 | |
| 5741 | auto ret = kvPairs.emplace( std::string(kv.key), std::string(kv.value) ); |
| 5742 | if ( !ret.second ) { |
| 5743 | // Duplicated key. We might want to handle this differently, |
| 5744 | // e.g. by overwriting the existing value? |
| 5745 | return {}; |
| 5746 | } |
| 5747 | } else if ( key == "out" ) { |
| 5748 | // Duplicated key |
| 5749 | if ( outputFileName ) { |
| 5750 | return {}; |
| 5751 | } |
| 5752 | outputFileName = static_cast<std::string>( value ); |
| 5753 | } else if ( key == "colour-mode" ) { |
| 5754 | // Duplicated key |
| 5755 | if ( colourMode ) { |
| 5756 | return {}; |
| 5757 | } |
| 5758 | colourMode = Detail::stringToColourMode( value ); |
| 5759 | // Parsing failed |
| 5760 | if ( !colourMode ) { |
| 5761 | return {}; |
| 5762 | } |
| 5763 | } else { |
| 5764 | // Unrecognized option |
| 5765 | return {}; |
| 5766 | } |
| 5767 | } |
| 5768 | |
| 5769 | return ReporterSpec{ CATCH_MOVE( parts[0] ), |
| 5770 | CATCH_MOVE( outputFileName ), |
| 5771 | CATCH_MOVE( colourMode ), |
| 5772 | CATCH_MOVE( kvPairs ) }; |
| 5773 | } |
| 5774 | |
| 5775 | ReporterSpec::ReporterSpec( |
no test coverage detected