mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-03 21:49:32 +01:00 
			
		
		
		
	StringRef conversions to/ from std::string
This commit is contained in:
		@@ -60,8 +60,7 @@ namespace Catch {
 | 
			
		||||
    
 | 
			
		||||
    StringRef::StringRef( String const& other ) noexcept
 | 
			
		||||
    :   m_start( other.c_str() ),
 | 
			
		||||
        m_size( other.size() ),
 | 
			
		||||
        m_data( nullptr )
 | 
			
		||||
        m_size( other.size() )
 | 
			
		||||
    {}
 | 
			
		||||
    
 | 
			
		||||
    StringRef::StringRef( String&& str ) noexcept
 | 
			
		||||
@@ -71,7 +70,11 @@ namespace Catch {
 | 
			
		||||
    {
 | 
			
		||||
        str.m_data = StringData::getEmpty();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    StringRef::StringRef( std::string const& stdString ) noexcept
 | 
			
		||||
    :   m_start( stdString.c_str() ),
 | 
			
		||||
        m_size( stdString.size() )
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    StringRef::~StringRef() noexcept {
 | 
			
		||||
        if( isOwned() )
 | 
			
		||||
            m_data->release();
 | 
			
		||||
@@ -81,6 +84,9 @@ namespace Catch {
 | 
			
		||||
        swap( other );
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
    StringRef::operator std::string() const {
 | 
			
		||||
        return std::string( m_start, m_size );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void StringRef::swap( StringRef& other ) noexcept {
 | 
			
		||||
        std::swap( m_start, other.m_start );
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
#define CATCH_STRINGREF_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <cstddef>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Catch {
 | 
			
		||||
    
 | 
			
		||||
@@ -43,9 +44,11 @@ namespace Catch {
 | 
			
		||||
        StringRef( char const* rawChars, size_type size ) noexcept;
 | 
			
		||||
        StringRef( String const& other ) noexcept;
 | 
			
		||||
        StringRef( String&& other ) noexcept;
 | 
			
		||||
        StringRef( std::string const& stdString ) noexcept;
 | 
			
		||||
        ~StringRef() noexcept;
 | 
			
		||||
        
 | 
			
		||||
        auto operator = ( StringRef other ) noexcept -> StringRef&;
 | 
			
		||||
        operator std::string() const;
 | 
			
		||||
 | 
			
		||||
        void swap( StringRef& other ) noexcept;
 | 
			
		||||
        
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user