StringRef conversions to/ from std::string
This commit is contained in:
parent
1aab791d67
commit
c659e0fd3d
3 changed files with 54 additions and 3 deletions
|
@ -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 );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue