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

summaryrefslogtreecommitdiffhomepage
path: root/include
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
parent1aab791d67a8a4072156db22d80c1a863dcdb593 (diff)
downloadcatch3-c659e0fd3dadd397dfed17e59a624fb693d77646.tar.gz
StringRef conversions to/ from std::string
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_stringref.cpp12
-rw-r--r--include/internal/catch_stringref.h3
2 files changed, 12 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 );
diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h
index f84ce99a..cde0667a 100644
--- a/include/internal/catch_stringref.h
+++ b/include/internal/catch_stringref.h
@@ -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;