diff --git a/CMakeLists.txt b/CMakeLists.txt index 92209dd2..ea35d24e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if(NOT DEFINED PROJECT_NAME) set(NOT_SUBPROJECT ON) endif() -project(Catch2 LANGUAGES CXX VERSION 2.7.0-develop.2) +project(Catch2 LANGUAGES CXX VERSION 2.7.0) # Provide path for scripts list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") diff --git a/include/internal/catch_enum_values_registry.cpp b/include/internal/catch_enum_values_registry.cpp index e974a67d..b94a70e5 100644 --- a/include/internal/catch_enum_values_registry.cpp +++ b/include/internal/catch_enum_values_registry.cpp @@ -19,11 +19,11 @@ namespace Catch { namespace Detail { std::vector parseEnums( StringRef enums ) { - auto enumValues = splitString( enums, ',' ); + auto enumValues = splitStringRef( enums, ',' ); std::vector parsed; parsed.reserve( enumValues.size() ); for( auto const& enumValue : enumValues ) { - auto identifiers = splitString( enumValue, ':' ); + auto identifiers = splitStringRef( enumValue, ':' ); parsed.push_back( Catch::trim( identifiers.back() ) ); } return parsed; diff --git a/include/internal/catch_string_manip.cpp b/include/internal/catch_string_manip.cpp index 60109335..9f459de0 100644 --- a/include/internal/catch_string_manip.cpp +++ b/include/internal/catch_string_manip.cpp @@ -67,8 +67,8 @@ namespace Catch { return replaced; } - std::vector splitString( StringRef str, char delimiter ) { - std::vector subStrings; + std::vector splitStringRef( StringRef str, char delimiter ) { + std::vector subStrings; std::size_t start = 0; for(std::size_t pos = 0; pos < str.size(); ++pos ) { if( str[pos] == delimiter ) { diff --git a/include/internal/catch_string_manip.h b/include/internal/catch_string_manip.h index 0f8176d6..32a7ec1e 100644 --- a/include/internal/catch_string_manip.h +++ b/include/internal/catch_string_manip.h @@ -22,8 +22,10 @@ namespace Catch { void toLowerInPlace( std::string& s ); std::string toLower( std::string const& s ); std::string trim( std::string const& str ); + + // !!! Be aware, returns refs into original string - make sure original string outlives them + std::vector splitStringRef( StringRef str, char delimiter ); bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); - std::vector splitString( StringRef str, char delimiter ); struct pluralise { pluralise( std::size_t count, std::string const& label ); diff --git a/projects/SelfTest/IntrospectiveTests/String.tests.cpp b/projects/SelfTest/IntrospectiveTests/String.tests.cpp index 007774a9..cb2c350c 100644 --- a/projects/SelfTest/IntrospectiveTests/String.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/String.tests.cpp @@ -205,11 +205,12 @@ TEST_CASE( "replaceInPlace", "[Strings][StringManip]" ) { TEST_CASE( "splitString", "[Strings]" ) { using namespace Catch::Matchers; - using Catch::splitString; + using Catch::splitStringRef; + using Catch::StringRef; - CHECK_THAT( splitString("", ',' ), Equals(std::vector() ) ); - CHECK_THAT( splitString("abc", ',' ), Equals(std::vector{"abc"} ) ); - CHECK_THAT( splitString("abc,def", ',' ), Equals(std::vector{"abc", "def"} ) ); + CHECK_THAT( splitStringRef("", ',' ), Equals(std::vector() ) ); + CHECK_THAT( splitStringRef("abc", ',' ), Equals(std::vector{"abc"} ) ); + CHECK_THAT( splitStringRef("abc,def", ',' ), Equals(std::vector{"abc", "def"} ) ); }