diff options
| author | Phil Nash | 2017-08-14 08:39:14 +0100 |
|---|---|---|
| committer | Phil Nash | 2017-08-14 08:39:14 +0100 |
| commit | c659e0fd3dadd397dfed17e59a624fb693d77646 (patch) | |
| tree | 32eb94110b2383c3d986e3e8b3d8415d715717ba /include/internal/catch_stringref.cpp | |
| parent | 1aab791d67a8a4072156db22d80c1a863dcdb593 (diff) | |
| download | catch3-c659e0fd3dadd397dfed17e59a624fb693d77646.tar.gz | |
StringRef conversions to/ from std::string
Diffstat (limited to 'include/internal/catch_stringref.cpp')
| -rw-r--r-- | include/internal/catch_stringref.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp index 44db6858..9a1eaf4c 100644 --- a/include/internal/catch_stringref.cpp +++ b/include/internal/catch_stringref.cpp @@ -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 ); |