Refactor serializeFilters implementation

This commit is contained in:
Martin Hořeňovský 2020-08-24 10:15:47 +02:00
parent 2a8e317cfb
commit 360b82620e
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 23 additions and 14 deletions

View File

@ -10,13 +10,14 @@
* of Catch2 has its own combined TU like this. * of Catch2 has its own combined TU like this.
*/ */
#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp> #include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/internal/catch_console_width.hpp> #include <catch2/internal/catch_console_width.hpp>
#include <catch2/internal/catch_errno_guard.hpp> #include <catch2/internal/catch_errno_guard.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <cfloat> #include <cfloat>
#include <cstdio> #include <cstdio>
#include <ostream>
namespace Catch { namespace Catch {
@ -52,18 +53,26 @@ namespace Catch {
return min >= 0 && duration >= min; return min >= 0 && duration >= min;
} }
std::string serializeFilters( std::vector<std::string> const& container ) { std::string serializeFilters( std::vector<std::string> const& filters ) {
ReusableStringStream oss; // We add a ' ' separator between each filter
bool first = true; size_t serialized_size = filters.size() - 1;
for ( auto&& filter : container ) { for (auto const& filter : filters) {
if ( !first ) serialized_size += filter.size();
oss << ' ';
else
first = false;
oss << filter;
} }
return oss.str();
std::string serialized;
serialized.reserve(serialized_size);
bool first = true;
for (auto const& filter : filters) {
if (!first) {
serialized.push_back(' ');
}
first = false;
serialized.append(filter);
}
return serialized;
} }
std::ostream& operator<<( std::ostream& out, lineOfChars value ) { std::ostream& operator<<( std::ostream& out, lineOfChars value ) {

View File

@ -15,7 +15,7 @@ namespace Catch {
//! Should the reporter show //! Should the reporter show
bool shouldShowDuration( IConfig const& config, double duration ); bool shouldShowDuration( IConfig const& config, double duration );
std::string serializeFilters( std::vector<std::string> const& container ); std::string serializeFilters( std::vector<std::string> const& filters );
struct lineOfChars { struct lineOfChars {
char c; char c;