mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
Removed templated StringRef ctor and added StringRef literal
This commit is contained in:
parent
c39109dce3
commit
e4a898eaaa
@ -15,7 +15,7 @@
|
|||||||
namespace {
|
namespace {
|
||||||
// Report the error condition
|
// Report the error condition
|
||||||
void reportFatal( char const * const message ) {
|
void reportFatal( char const * const message ) {
|
||||||
Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( Catch::StringRef::fromRaw( message ) );
|
Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
void RunContext::resetAssertionInfo() {
|
void RunContext::resetAssertionInfo() {
|
||||||
m_lastAssertionInfo.macroName = StringRef();
|
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) {
|
bool RunContext::sectionStarted(SectionInfo const & sectionInfo, Counts & assertions) {
|
||||||
|
@ -17,11 +17,9 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
auto StringRef::fromRaw( char const* rawChars ) -> StringRef {
|
StringRef::StringRef( char const* rawChars ) noexcept
|
||||||
return rawChars
|
: StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
|
||||||
? StringRef( rawChars,static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
|
{}
|
||||||
: StringRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
StringRef::operator std::string() const {
|
StringRef::operator std::string() const {
|
||||||
return std::string( m_start, m_size );
|
return std::string( m_start, m_size );
|
||||||
|
@ -23,10 +23,12 @@ namespace Catch {
|
|||||||
/// visible - but it does mean (substring) StringRefs should not be shared between
|
/// visible - but it does mean (substring) StringRefs should not be shared between
|
||||||
/// threads.
|
/// threads.
|
||||||
class StringRef {
|
class StringRef {
|
||||||
friend struct StringRefTestAccess;
|
public:
|
||||||
|
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend struct StringRefTestAccess;
|
||||||
|
|
||||||
char const* m_start;
|
char const* m_start;
|
||||||
size_type m_size;
|
size_type m_size;
|
||||||
|
|
||||||
@ -54,11 +56,7 @@ namespace Catch {
|
|||||||
other.m_data = nullptr;
|
other.m_data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t Size>
|
StringRef( char const* rawChars ) noexcept;
|
||||||
StringRef( char const(& rawChars)[Size] ) noexcept
|
|
||||||
: m_start( rawChars ),
|
|
||||||
m_size( static_cast<size_type>( Size-1 ) )
|
|
||||||
{}
|
|
||||||
|
|
||||||
StringRef( char const* rawChars, size_type size ) noexcept
|
StringRef( char const* rawChars, size_type size ) noexcept
|
||||||
: m_start( rawChars ),
|
: m_start( rawChars ),
|
||||||
@ -82,8 +80,6 @@ namespace Catch {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto fromRaw( char const *rawChars ) -> StringRef;
|
|
||||||
|
|
||||||
operator std::string() const;
|
operator std::string() const;
|
||||||
|
|
||||||
void swap( StringRef& other ) noexcept;
|
void swap( StringRef& other ) noexcept;
|
||||||
@ -120,6 +116,10 @@ namespace Catch {
|
|||||||
|
|
||||||
auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
|
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
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_STRINGREF_H_INCLUDED
|
#endif // CATCH_STRINGREF_H_INCLUDED
|
||||||
|
@ -35,7 +35,7 @@ auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct NameAndTags {
|
struct NameAndTags {
|
||||||
NameAndTags( StringRef name_ = "", StringRef tags_ = "" ) noexcept;
|
NameAndTags( StringRef name_ = StringRef(), StringRef tags_ = StringRef() ) noexcept;
|
||||||
StringRef name;
|
StringRef name;
|
||||||
StringRef tags;
|
StringRef tags;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user