mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	Changed splitString to splitStringRef
Now takes and returns StringRefs
This commit is contained in:
		| @@ -6,7 +6,7 @@ if(NOT DEFINED PROJECT_NAME) | |||||||
|   set(NOT_SUBPROJECT ON) |   set(NOT_SUBPROJECT ON) | ||||||
| endif() | endif() | ||||||
|  |  | ||||||
| project(Catch2 LANGUAGES CXX VERSION 2.7.0-develop.2) | project(Catch2 LANGUAGES CXX VERSION 2.7.0) | ||||||
|  |  | ||||||
| # Provide path for scripts | # Provide path for scripts | ||||||
| list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") | ||||||
|   | |||||||
| @@ -19,11 +19,11 @@ namespace Catch { | |||||||
|     namespace Detail { |     namespace Detail { | ||||||
|  |  | ||||||
|         std::vector<std::string> parseEnums( StringRef enums ) { |         std::vector<std::string> parseEnums( StringRef enums ) { | ||||||
|             auto enumValues = splitString( enums, ',' ); |             auto enumValues = splitStringRef( enums, ',' ); | ||||||
|             std::vector<std::string> parsed; |             std::vector<std::string> parsed; | ||||||
|             parsed.reserve( enumValues.size() ); |             parsed.reserve( enumValues.size() ); | ||||||
|             for( auto const& enumValue : enumValues ) { |             for( auto const& enumValue : enumValues ) { | ||||||
|                 auto identifiers = splitString( enumValue, ':' ); |                 auto identifiers = splitStringRef( enumValue, ':' ); | ||||||
|                 parsed.push_back( Catch::trim( identifiers.back() ) ); |                 parsed.push_back( Catch::trim( identifiers.back() ) ); | ||||||
|             } |             } | ||||||
|             return parsed; |             return parsed; | ||||||
|   | |||||||
| @@ -67,8 +67,8 @@ namespace Catch { | |||||||
|         return replaced; |         return replaced; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     std::vector<std::string> splitString( StringRef str, char delimiter ) { |     std::vector<StringRef> splitStringRef( StringRef str, char delimiter ) { | ||||||
|         std::vector<std::string> subStrings; |         std::vector<StringRef> subStrings; | ||||||
|         std::size_t start = 0; |         std::size_t start = 0; | ||||||
|         for(std::size_t pos = 0; pos < str.size(); ++pos ) { |         for(std::size_t pos = 0; pos < str.size(); ++pos ) { | ||||||
|             if( str[pos] == delimiter ) { |             if( str[pos] == delimiter ) { | ||||||
|   | |||||||
| @@ -22,8 +22,10 @@ namespace Catch { | |||||||
|     void toLowerInPlace( std::string& s ); |     void toLowerInPlace( std::string& s ); | ||||||
|     std::string toLower( std::string const& s ); |     std::string toLower( std::string const& s ); | ||||||
|     std::string trim( std::string const& str ); |     std::string trim( std::string const& str ); | ||||||
|  |  | ||||||
|  |     // !!! Be aware, returns refs into original string - make sure original string outlives them | ||||||
|  |     std::vector<StringRef> splitStringRef( StringRef str, char delimiter ); | ||||||
|     bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); |     bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); | ||||||
|     std::vector<std::string> splitString( StringRef str, char delimiter ); |  | ||||||
|  |  | ||||||
|     struct pluralise { |     struct pluralise { | ||||||
|         pluralise( std::size_t count, std::string const& label ); |         pluralise( std::size_t count, std::string const& label ); | ||||||
|   | |||||||
| @@ -205,11 +205,12 @@ TEST_CASE( "replaceInPlace", "[Strings][StringManip]" ) { | |||||||
|  |  | ||||||
| TEST_CASE( "splitString", "[Strings]" ) { | TEST_CASE( "splitString", "[Strings]" ) { | ||||||
|     using namespace Catch::Matchers; |     using namespace Catch::Matchers; | ||||||
|     using Catch::splitString; |     using Catch::splitStringRef; | ||||||
|  |     using Catch::StringRef; | ||||||
|  |  | ||||||
|     CHECK_THAT( splitString("", ',' ), Equals(std::vector<std::string>() ) ); |     CHECK_THAT( splitStringRef("", ',' ), Equals(std::vector<StringRef>() ) ); | ||||||
|     CHECK_THAT( splitString("abc", ',' ), Equals(std::vector<std::string>{"abc"} ) ); |     CHECK_THAT( splitStringRef("abc", ',' ), Equals(std::vector<StringRef>{"abc"} ) ); | ||||||
|     CHECK_THAT( splitString("abc,def", ',' ), Equals(std::vector<std::string>{"abc", "def"} ) ); |     CHECK_THAT( splitStringRef("abc,def", ',' ), Equals(std::vector<StringRef>{"abc", "def"} ) ); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash