Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_stringref.cpp
diff options
context:
space:
mode:
authorPhil Nash2017-08-14 08:39:14 +0100
committerPhil Nash2017-08-14 08:39:14 +0100
commitc659e0fd3dadd397dfed17e59a624fb693d77646 (patch)
tree32eb94110b2383c3d986e3e8b3d8415d715717ba /include/internal/catch_stringref.cpp
parent1aab791d67a8a4072156db22d80c1a863dcdb593 (diff)
downloadcatch3-c659e0fd3dadd397dfed17e59a624fb693d77646.tar.gz
StringRef conversions to/ from std::string
Diffstat (limited to 'include/internal/catch_stringref.cpp')
-rw-r--r--include/internal/catch_stringref.cpp12
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 );