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

summaryrefslogtreecommitdiffhomepage
path: root/include/internal
diff options
context:
space:
mode:
authorPhil Nash2017-11-21 11:08:08 +0000
committerPhil Nash2017-11-21 11:08:39 +0000
commite4a898eaaa0f0458cd5d9f6d63a311366aa8eb0a (patch)
treecbeaff5db4186e7a4c17bd0d9a63dbcda5aefcfa /include/internal
parentc39109dce37ce4afad9c6e2a002b32c5313654b9 (diff)
downloadcatch3-e4a898eaaa0f0458cd5d9f6d63a311366aa8eb0a.tar.gz
Removed templated StringRef ctor and added StringRef literal
Diffstat (limited to 'include/internal')
-rw-r--r--include/internal/catch_fatal_condition.cpp2
-rw-r--r--include/internal/catch_run_context.cpp2
-rw-r--r--include/internal/catch_stringref.cpp8
-rw-r--r--include/internal/catch_stringref.h18
-rw-r--r--include/internal/catch_test_registry.h2
5 files changed, 15 insertions, 17 deletions
diff --git a/include/internal/catch_fatal_condition.cpp b/include/internal/catch_fatal_condition.cpp
index ac2863d2..39b63455 100644
--- a/include/internal/catch_fatal_condition.cpp
+++ b/include/internal/catch_fatal_condition.cpp
@@ -15,7 +15,7 @@
namespace {
// Report the error condition
void reportFatal( char const * const message ) {
- Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( Catch::StringRef::fromRaw( message ) );
+ Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message );
}
}
diff --git a/include/internal/catch_run_context.cpp b/include/internal/catch_run_context.cpp
index 98cc655a..d6ab1576 100644
--- a/include/internal/catch_run_context.cpp
+++ b/include/internal/catch_run_context.cpp
@@ -132,7 +132,7 @@ namespace Catch {
}
void RunContext::resetAssertionInfo() {
m_lastAssertionInfo.macroName = StringRef();
- m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}";
+ m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr;
}
bool RunContext::sectionStarted(SectionInfo const & sectionInfo, Counts & assertions) {
diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp
index 127406ff..bac8b1d8 100644
--- a/include/internal/catch_stringref.cpp
+++ b/include/internal/catch_stringref.cpp
@@ -17,11 +17,9 @@
#include <cstring>
namespace Catch {
- auto StringRef::fromRaw( char const* rawChars ) -> StringRef {
- return rawChars
- ? StringRef( rawChars,static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
- : StringRef();
- }
+ StringRef::StringRef( char const* rawChars ) noexcept
+ : StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
+ {}
StringRef::operator std::string() const {
return std::string( m_start, m_size );
diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h
index 29dcde26..62d97658 100644
--- a/include/internal/catch_stringref.h
+++ b/include/internal/catch_stringref.h
@@ -23,10 +23,12 @@ namespace Catch {
/// visible - but it does mean (substring) StringRefs should not be shared between
/// threads.
class StringRef {
+ public:
+ using size_type = std::size_t;
+
+ private:
friend struct StringRefTestAccess;
- using size_type = std::size_t;
-
char const* m_start;
size_type m_size;
@@ -54,11 +56,7 @@ namespace Catch {
other.m_data = nullptr;
}
- template<size_t Size>
- StringRef( char const(& rawChars)[Size] ) noexcept
- : m_start( rawChars ),
- m_size( static_cast<size_type>( Size-1 ) )
- {}
+ StringRef( char const* rawChars ) noexcept;
StringRef( char const* rawChars, size_type size ) noexcept
: m_start( rawChars ),
@@ -82,8 +80,6 @@ namespace Catch {
return *this;
}
- static auto fromRaw( char const *rawChars ) -> StringRef;
-
operator std::string() const;
void swap( StringRef& other ) noexcept;
@@ -120,6 +116,10 @@ namespace Catch {
auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
+ inline auto operator ""_sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
+ return StringRef( rawChars, size );
+ }
+
} // namespace Catch
#endif // CATCH_STRINGREF_H_INCLUDED
diff --git a/include/internal/catch_test_registry.h b/include/internal/catch_test_registry.h
index afba1dbc..84001018 100644
--- a/include/internal/catch_test_registry.h
+++ b/include/internal/catch_test_registry.h
@@ -35,7 +35,7 @@ auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
}
struct NameAndTags {
- NameAndTags( StringRef name_ = "", StringRef tags_ = "" ) noexcept;
+ NameAndTags( StringRef name_ = StringRef(), StringRef tags_ = StringRef() ) noexcept;
StringRef name;
StringRef tags;
};