diff options
| author | Martin Hořeňovský | 2017-05-02 23:51:03 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2017-05-02 23:51:03 +0200 |
| commit | 33ed1773f40b406dbf3b7201bf52694bd86b1503 (patch) | |
| tree | 57aa3b7d82e3fcc2b8b99222515ec2d26b22a66a /include | |
| parent | 40130e59b4b13f9e4c9962a8ffb19448c94b7c0f (diff) | |
| download | catch3-33ed1773f40b406dbf3b7201bf52694bd86b1503.tar.gz | |
Reworked stringification layer, removed Catch::toString
Now the order of stringification checks is
1) StringMaker specialization
2) operator<<
toString overloads and specializations have been removed.
Diffstat (limited to 'include')
| -rw-r--r-- | include/catch.hpp | 8 | ||||
| -rw-r--r-- | include/internal/catch_approx.hpp | 10 | ||||
| -rw-r--r-- | include/internal/catch_expression_lhs.hpp | 8 | ||||
| -rw-r--r-- | include/internal/catch_matchers_vector.h | 6 | ||||
| -rw-r--r-- | include/internal/catch_tostring.h | 440 | ||||
| -rw-r--r-- | include/internal/catch_tostring.hpp | 241 | ||||
| -rw-r--r-- | include/reporters/catch_reporter_junit.hpp | 2 |
7 files changed, 404 insertions, 311 deletions
diff --git a/include/catch.hpp b/include/catch.hpp index 236ec38e..29132e0d 100644 --- a/include/catch.hpp +++ b/include/catch.hpp @@ -127,8 +127,8 @@ LeakDetector leakDetector; #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) -#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) ) -#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) ) +#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) +#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) @@ -194,8 +194,8 @@ LeakDetector leakDetector; #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) -#define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) ) -#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) ) +#define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) +#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) diff --git a/include/internal/catch_approx.hpp b/include/internal/catch_approx.hpp index 66576428..9c974f6c 100644 --- a/include/internal/catch_approx.hpp +++ b/include/internal/catch_approx.hpp @@ -114,7 +114,7 @@ namespace Detail { std::string toString() const { std::ostringstream oss; - oss << "Approx( " << Catch::toString( m_value ) << " )"; + oss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; return oss.str(); } @@ -127,9 +127,11 @@ namespace Detail { } template<> -inline std::string toString<Detail::Approx>( Detail::Approx const& value ) { - return value.toString(); -} +struct StringMaker<Catch::Detail::Approx> { + std::string operator()(Catch::Detail::Approx const& value) { + return value.toString(); + } +}; } // end namespace Catch diff --git a/include/internal/catch_expression_lhs.hpp b/include/internal/catch_expression_lhs.hpp index 756a07f6..1ac339b4 100644 --- a/include/internal/catch_expression_lhs.hpp +++ b/include/internal/catch_expression_lhs.hpp @@ -81,7 +81,7 @@ public: } virtual void reconstructExpression( std::string& dest ) const override { - dest = Catch::toString( m_truthy ); + dest = ::Catch::Detail::stringify( m_truthy ); } private: @@ -120,8 +120,8 @@ public: } virtual void reconstructExpression( std::string& dest ) const override { - std::string lhs = Catch::toString( m_lhs ); - std::string rhs = Catch::toString( m_rhs ); + std::string lhs = ::Catch::Detail::stringify( m_lhs ); + std::string rhs = ::Catch::Detail::stringify( m_rhs ); char delim = lhs.size() + rhs.size() < 40 && lhs.find('\n') == std::string::npos && rhs.find('\n') == std::string::npos ? ' ' : '\n'; @@ -155,7 +155,7 @@ public: virtual void reconstructExpression( std::string& dest ) const override { std::string matcherAsString = m_matcher.toString(); - dest = Catch::toString( m_arg ); + dest = ::Catch::Detail::stringify( m_arg ); dest += ' '; if( matcherAsString == Detail::unprintableString ) dest += m_matcherString; diff --git a/include/internal/catch_matchers_vector.h b/include/internal/catch_matchers_vector.h index 11aee020..e80f7e12 100644 --- a/include/internal/catch_matchers_vector.h +++ b/include/internal/catch_matchers_vector.h @@ -25,7 +25,7 @@ namespace Matchers { } virtual std::string describe() const override { - return "Contains: " + Catch::toString( m_comparator ); + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); } T const& m_comparator; @@ -46,7 +46,7 @@ namespace Matchers { return true; } virtual std::string describe() const override { - return "Contains: " + Catch::toString( m_comparator ); + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); } std::vector<T> const& m_comparator; @@ -70,7 +70,7 @@ namespace Matchers { return true; } virtual std::string describe() const override { - return "Equals: " + Catch::toString( m_comparator ); + return "Equals: " + ::Catch::Detail::stringify( m_comparator ); } std::vector<T> const& m_comparator; }; diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index f72eeca3..02eb0d6f 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -24,226 +24,296 @@ #include <type_traits> +#include <string> + +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); + namespace Catch { + // Bring in operator<< from global namespace into Catch namespace + using ::operator<<; -// Why we're here. -template<typename T> -std::string toString( T const& value ); - -// Built in overloads - -std::string toString( std::string const& value ); -std::string toString( std::wstring const& value ); -std::string toString( const char* const value ); -std::string toString( char* const value ); -std::string toString( const wchar_t* const value ); -std::string toString( wchar_t* const value ); -std::string toString( int value ); -std::string toString( unsigned long value ); -std::string toString( unsigned int value ); -std::string toString( const double value ); -std::string toString( const float value ); -std::string toString( bool value ); -std::string toString( char value ); -std::string toString( signed char value ); -std::string toString( unsigned char value ); - -std::string toString( long long value ); -std::string toString( unsigned long long value ); - -std::string toString( std::nullptr_t ); + namespace Detail { + std::string rawMemoryToString( const void *object, std::size_t size ); -#ifdef __OBJC__ - std::string toString( NSString const * const& nsstring ); - std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ); - std::string toString( NSObject* const& nsObject ); -#endif + template<typename T> + std::string rawMemoryToString( const T& object ) { + return rawMemoryToString( &object, sizeof(object) ); + } + template<typename T> + class IsStreamInsertable { + template<typename SS, typename TT> + static auto test(int) + -> decltype(std::declval<SS&>() << std::declval<TT>(), std::true_type()); + + template<typename, typename> + static auto test(...)->std::false_type; + + public: + static const bool value = decltype(test<std::ostream, const T&>(0))::value; + }; + + } // namespace Detail + + // If we decide for C++14, change these to enable_if_ts + template <typename T> + struct StringMaker { + template <typename Fake = T> + typename std::enable_if<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type + operator()(const Fake& t) { + std::stringstream sstr; + sstr << t; + return sstr.str(); + } -namespace Detail { + template <typename Fake = T> + typename std::enable_if<!::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type + operator()(const Fake&) { + return "{?}"; + } + }; - extern const std::string unprintableString; + namespace Detail { - template<typename T> - class IsStreamInsertable { - template<typename SS, typename TT> - static auto test(int) - -> decltype( std::declval<SS&>() << std::declval<TT>(), std::true_type() ); + extern const std::string unprintableString; - template<typename, typename> - static auto test(...) -> std::false_type; + // This function dispatches all stringification requests inside of Catch. + // Should be preferably called fully qualified, like ::Catch::Detail::stringify + template <typename T> + std::string stringify(const T& e) { + return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>{}(e); + } + + } // namespace Detail + + + // Some predefined specializations + + template<> + struct StringMaker<std::string> { + std::string operator()(const std::string& str); + }; + template<> + struct StringMaker<std::wstring> { + std::string operator()(const std::wstring& wstr); + }; + + template<> + struct StringMaker<char const *> { + std::string operator()(char const * str); + }; + template<> + struct StringMaker<char *> { + std::string operator()(char * str); + }; + template<> + struct StringMaker<wchar_t const *> { + std::string operator()(wchar_t const * str); + }; + template<> + struct StringMaker<wchar_t *> { + std::string operator()(wchar_t * str); + }; - public: - static const bool value = decltype(test<std::ostream,const T&>(0))::value; + template<int SZ> + struct StringMaker<char[SZ]> { + std::string operator()(const char* str) { + return ::Catch::Detail::stringify(std::string{ str }); + } + }; + template<int SZ> + struct StringMaker<signed char[SZ]> { + std::string operator()(const char* str) { + return ::Catch::Detail::stringify(std::string{ str }); + } + }; + template<int SZ> + struct StringMaker<unsigned char[SZ]> { + std::string operator()(const char* str) { + return ::Catch::Detail::stringify(std::string{ str }); + } }; + template<> + struct StringMaker<int> { + std::string operator()(int value); + }; + template<> + struct StringMaker<long> { + std::string operator()(long value); + }; + template<> + struct StringMaker<long long> { + std::string operator()(long long value); + }; + template<> + struct StringMaker<unsigned int> { + std::string operator()(unsigned int value); + }; + template<> + struct StringMaker<unsigned long> { + std::string operator()(unsigned long value); + }; + template<> + struct StringMaker<unsigned long long> { + std::string operator()(unsigned long long value); + }; - template<typename T, - bool IsEnum = std::is_enum<T>::value - > - struct EnumStringMaker - { - static std::string convert( T const& ) { return unprintableString; } + template<> + struct StringMaker<bool> { + std::string operator()(bool b); }; - template<typename T> - struct EnumStringMaker<T,true> - { - static std::string convert( T const& v ) - { - return ::Catch::toString( - static_cast<typename std::underlying_type<T>::type>(v) - ); + template<> + struct StringMaker<char> { + std::string operator()(char c); + }; + template<> + struct StringMaker<signed char> { + std::string operator()(signed char c); + }; + template<> + struct StringMaker<unsigned char> { + std::string operator()(unsigned char c); + }; + + template<> + struct StringMaker<nullptr_t> { + std::string operator()(std::nullptr_t); + }; + + template<> + struct StringMaker<float> { + std::string operator()(float value); + }; + template<> + struct StringMaker<double> { + std::string operator()(double value); + }; + + template <typename T> + struct StringMaker<T*> { + template <typename U> + std::string operator()(U* p) { + if (p) { + return ::Catch::Detail::rawMemoryToString(p); + } else { + return "nullptr"; + } } }; - template<bool C> - struct StringMakerBase { - template<typename T> - static std::string convert( T const& v ) - { - return EnumStringMaker<T>::convert( v ); + template <typename R, typename C> + struct StringMaker<R C::*> { + std::string operator()(R C::* p) { + if (p) { + return ::Catch::Detail::rawMemoryToString(p); + } else { + return "nullptr"; + } } }; - template<> - struct StringMakerBase<true> { - template<typename T> - static std::string convert( T const& _value ) { + namespace Detail { + template<typename InputIterator> + std::string rangeToString(InputIterator first, InputIterator last) { std::ostringstream oss; - oss << _value; + oss << "{ "; + if (first != last) { + oss << ::Catch::Detail::stringify(*first); + for (++first; first != last; ++first) + oss << ", " << ::Catch::Detail::stringify(*first); + } + oss << " }"; return oss.str(); } + } + + template<typename T, typename Allocator> + struct StringMaker<std::vector<T, Allocator> > { + std::string operator()( std::vector<T,Allocator> const& v ) { + return ::Catch::Detail::rangeToString( v.begin(), v.end() ); + } }; - std::string rawMemoryToString( const void *object, std::size_t size ); + // === Pair === + template<typename T1, typename T2> + struct StringMaker<std::pair<T1, T2> > { + std::string operator()(const std::pair<T1, T2>& pair) { + std::ostringstream oss; + oss << "{ " + << ::Catch::Detail::stringify(pair.first) + << ", " + << ::Catch::Detail::stringify(pair.second) + << " }"; + return oss.str(); + } + }; - template<typename T> - inline std::string rawMemoryToString( const T& object ) { - return rawMemoryToString( &object, sizeof(object) ); - } -} // end namespace Detail -template<typename T> -struct StringMaker : - Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {}; + namespace Detail { + template< + typename Tuple, + std::size_t N = 0, + bool = (N < std::tuple_size<Tuple>::value) + > + struct TupleElementPrinter { + static void print(const Tuple& tuple, std::ostream& os) { + os << (N ? ", " : " ") + << ::Catch::Detail::stringify(std::get<N>(tuple)); + TupleElementPrinter<Tuple, N + 1>::print(tuple, os); + } + }; + + template< + typename Tuple, + std::size_t N + > + struct TupleElementPrinter<Tuple, N, false> { + static void print(const Tuple&, std::ostream&) {} + }; -template<typename T> -struct StringMaker<T*> { - template<typename U> - static std::string convert( U* p ) { - if( !p ) - return "NULL"; - else - return Detail::rawMemoryToString( p ); } -}; - -template<typename R, typename C> -struct StringMaker<R C::*> { - static std::string convert( R C::* p ) { - if( !p ) - return "NULL"; - else - return Detail::rawMemoryToString( p ); - } -}; - -namespace Detail { - template<typename InputIterator> - std::string rangeToString( InputIterator first, InputIterator last ); -} - -//template<typename T, typename Allocator> -//struct StringMaker<std::vector<T, Allocator> > { -// static std::string convert( std::vector<T,Allocator> const& v ) { -// return Detail::rangeToString( v.begin(), v.end() ); -// } -//}; - -template<typename T, typename Allocator> -std::string toString( std::vector<T,Allocator> const& v ) { - return Detail::rangeToString( v.begin(), v.end() ); -} - - - -// toString for tuples -namespace TupleDetail { - template< - typename Tuple, - std::size_t N = 0, - bool = (N < std::tuple_size<Tuple>::value) - > - struct ElementPrinter { - static void print( const Tuple& tuple, std::ostream& os ) - { - os << ( N ? ", " : " " ) - << Catch::toString(std::get<N>(tuple)); - ElementPrinter<Tuple,N+1>::print(tuple,os); - } - }; - - template< - typename Tuple, - std::size_t N - > - struct ElementPrinter<Tuple,N,false> { - static void print( const Tuple&, std::ostream& ) {} - }; - -} - -template<typename ...Types> -struct StringMaker<std::tuple<Types...>> { - - static std::string convert( const std::tuple<Types...>& tuple ) - { - std::ostringstream os; - os << '{'; - TupleDetail::ElementPrinter<std::tuple<Types...>>::print( tuple, os ); - os << " }"; - return os.str(); - } -}; -namespace Detail { - template<typename T> - std::string makeString( T const& value ) { - return StringMaker<T>::convert( value ); - } -} // end namespace Detail - -/// \brief converts any type to a string -/// -/// The default template forwards on to ostringstream - except when an -/// ostringstream overload does not exist - in which case it attempts to detect -/// that and writes {?}. -/// Overload (not specialise) this template for custom typs that you don't want -/// to provide an ostream overload for. -template<typename T> -std::string toString( T const& value ) { - return StringMaker<T>::convert( value ); -} + template<typename ...Types> + struct StringMaker<std::tuple<Types...>> { + std::string operator()(const std::tuple<Types...>& tuple) { + std::ostringstream os; + os << '{'; + Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, os); + os << " }"; + return os.str(); + } + }; - namespace Detail { - template<typename InputIterator> - std::string rangeToString( InputIterator first, InputIterator last ) { - std::ostringstream oss; - oss << "{ "; - if( first != last ) { - oss << Catch::toString( *first ); - for( ++first ; first != last ; ++first ) - oss << ", " << Catch::toString( *first ); + template<typename T> + struct EnumStringMaker { + std::string operator()(const T& t) { + return ::Catch::Detail::stringify(static_cast<typename std::underlying_type<T>::type>(t)); } - oss << " }"; - return oss.str(); - } -} + }; + +#ifdef __OBJC__ + template<> + struct StringMaker<NSString const *> { + std::string operator()(NSString const* const& nsstring); + }; + template<> + struct StringMaker<NSString * CATCH_ARC_STRONG> { + std::string operator()(NSString * CATCH_ARC_STRONG const& nsstring); + }; + template<> + struct StringMaker<NSObject *> { + std::string operator()(NSObject* const& nsObject); + }; +#endif + -} // end namespace Catch +} // namespace Catch #endif // TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED diff --git a/include/internal/catch_tostring.hpp b/include/internal/catch_tostring.hpp index f20c41a2..8fc3c89e 100644 --- a/include/internal/catch_tostring.hpp +++ b/include/internal/catch_tostring.hpp @@ -35,8 +35,7 @@ namespace Detail { }; } - std::string rawMemoryToString( const void *object, std::size_t size ) - { + std::string rawMemoryToString( const void *object, std::size_t size ) { // Reverse order for little endian architectures int i = 0, end = static_cast<int>( size ), inc = 1; if( Endianness::which() == Endianness::Little ) { @@ -53,155 +52,177 @@ namespace Detail { } } -std::string toString( std::string const& value ) { - std::string s = value; - if( getCurrentContext().getConfig()->showInvisibles() ) { - for(size_t i = 0; i < s.size(); ++i ) { - std::string subs; - switch( s[i] ) { - case '\n': subs = "\\n"; break; - case '\t': subs = "\\t"; break; - default: break; - } - if( !subs.empty() ) { - s = s.substr( 0, i ) + subs + s.substr( i+1 ); - ++i; - } + +template<typename T> +std::string fpToString( T value, int precision ) { + std::ostringstream oss; + oss << std::setprecision( precision ) + << std::fixed + << value; + std::string d = oss.str(); + std::size_t i = d.find_last_not_of( '0' ); + if( i != std::string::npos && i != d.size()-1 ) { + if( d[i] == '.' ) + i++; + d = d.substr( 0, i+1 ); + } + return d; +} + + +//// ======================================================= //// +// +// Out-of-line defs for full specialization of StringMaker +// +//// ======================================================= //// + +std::string StringMaker<std::string>::operator()(const std::string& str) { + if (!getCurrentContext().getConfig()->showInvisibles()) { + return '"' + str + '"'; + } + + std::string s("\""); + for (char c : str) { + switch (c) { + case '\n': + s.append("\\n"); + break; + case '\t': + s.append("\\t"); + break; + default: + s.push_back(c); + break; } } - return '"' + s + '"'; + s.append("\""); + return s; } -std::string toString( std::wstring const& value ) { +std::string StringMaker<std::wstring>::operator()(const std::wstring& wstr) { std::string s; - s.reserve( value.size() ); - for(size_t i = 0; i < value.size(); ++i ) - s += value[i] <= 0xff ? static_cast<char>( value[i] ) : '?'; - return Catch::toString( s ); + s.reserve(wstr.size()); + for (auto c : wstr) { + s += (c <= 0xff) ? static_cast<char>(c) : '?'; + } + return ::Catch::Detail::stringify(s); } -std::string toString( const char* const value ) { - return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" ); +std::string StringMaker<char const*>::operator()(char const* str) { + if (str) { + return ::Catch::Detail::stringify(std::string{ str }); + } else { + return{ "{null string}" }; + } } - -std::string toString( char* const value ) { - return Catch::toString( static_cast<const char*>( value ) ); +std::string StringMaker<char*>::operator()(char* str) { + if (str) { + return ::Catch::Detail::stringify(std::string{ str }); + } else { + return{ "{null string}" }; + } } - -std::string toString( const wchar_t* const value ) -{ - return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" ); +std::string StringMaker<wchar_t const*>::operator()(wchar_t const * str) { + if (str) { + return ::Catch::Detail::stringify(std::wstring{ str }); + } else { + return{ "{null string}" }; + } } - -std::string toString( wchar_t* const value ) -{ - return Catch::toString( static_cast<const wchar_t*>( value ) ); +std::string StringMaker<wchar_t *>::operator()(wchar_t * str) { + if (str) { + return ::Catch::Detail::stringify(std::wstring{ str }); + } else { + return{ "{null string}" }; + } } -std::string toString( int value ) { - std::ostringstream oss; - oss << value; - if( value > Detail::hexThreshold ) - oss << " (0x" << std::hex << value << ')'; - return oss.str(); -} -std::string toString( unsigned long value ) { +std::string StringMaker<int>::operator()(int value) { + return ::Catch::Detail::stringify(static_cast<long long>(value)); +} +std::string StringMaker<long>::operator()(long value) { + return ::Catch::Detail::stringify(static_cast<long long>(value)); +} +std::string StringMaker<long long>::operator()(long long value) { std::ostringstream oss; oss << value; - if( value > Detail::hexThreshold ) + if (value > Detail::hexThreshold) { oss << " (0x" << std::hex << value << ')'; + } return oss.str(); } -std::string toString( unsigned int value ) { - return Catch::toString( static_cast<unsigned long>( value ) ); +std::string StringMaker<unsigned int>::operator()(unsigned int value) { + return ::Catch::Detail::stringify(static_cast<unsigned long long>(value)); } - -template<typename T> -std::string fpToString( T value, int precision ) { +std::string StringMaker<unsigned long>::operator()(unsigned long value) { + return ::Catch::Detail::stringify(static_cast<unsigned long long>(value)); +} +std::string StringMaker<unsigned long long>::operator()(unsigned long long value) { std::ostringstream oss; - oss << std::setprecision( precision ) - << std::fixed - << value; - std::string d = oss.str(); - std::size_t i = d.find_last_not_of( '0' ); - if( i != std::string::npos && i != d.size()-1 ) { - if( d[i] == '.' ) - i++; - d = d.substr( 0, i+1 ); + oss << value; + if (value > Detail::hexThreshold) { + oss << " (0x" << std::hex << value << ')'; } - return d; + return oss.str(); } -std::string toString( const double value ) { - return fpToString( value, 10 ); -} -std::string toString( const float value ) { - return fpToString( value, 5 ) + 'f'; -} -std::string toString( bool value ) { - return value ? "true" : "false"; +std::string StringMaker<bool>::operator()(bool b) { + return b ? "true" : "false"; } -std::string toString( char value ) { - if ( value == '\r' ) +std::string StringMaker<char>::operator()(char value) { + if (value == '\r') { return "'\\r'"; - if ( value == '\f' ) + } else if (value == '\f') { return "'\\f'"; - if ( value == '\n' ) + } else if (value == '\n') { return "'\\n'"; - if ( value == '\t' ) + } else if (value == '\t') { return "'\\t'"; - if ( '\0' <= value && value < ' ' ) - return toString( static_cast<unsigned int>( value ) ); - char chstr[] = "' '"; - chstr[1] = value; - return chstr; + } else if ('\0' <= value && value < ' ') { + return ::Catch::Detail::stringify(static_cast<unsigned int>(value)); + } else { + char chstr[] = "' '"; + chstr[1] = value; + return chstr; + } } - -std::string toString( signed char value ) { - return toString( static_cast<char>( value ) ); +std::string StringMaker<signed char>::operator()(signed char c) { + return ::Catch::Detail::stringify(static_cast<char>(c)); +} +std::string StringMaker<unsigned char>::operator()(unsigned char c) { + return ::Catch::Detail::stringify(static_cast<char>(c)); } -std::string toString( unsigned char value ) { - return toString( static_cast<char>( value ) ); +std::string StringMaker<nullptr_t>::operator()(std::nullptr_t) { + return "nullptr"; } -std::string toString( long long value ) { - std::ostringstream oss; - oss << value; - if( value > Detail::hexThreshold ) - oss << " (0x" << std::hex << value << ')'; - return oss.str(); +std::string StringMaker<float>::operator()(float value) { + return fpToString(value, 5) + 'f'; } -std::string toString( unsigned long long value ) { - std::ostringstream oss; - oss << value; - if( value > Detail::hexThreshold ) - oss << " (0x" << std::hex << value << ')'; - return oss.str(); +std::string StringMaker<double>::operator()(double value) { + return fpToString(value, 10); } -std::string toString( std::nullptr_t ) { - return "nullptr"; -} #ifdef __OBJC__ - std::string toString( NSString const * const& nsstring ) { - if( !nsstring ) - return "nil"; - return "@" + toString([nsstring UTF8String]); - } - std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) { - if( !nsstring ) - return "nil"; - return "@" + toString([nsstring UTF8String]); - } - std::string toString( NSObject* const& nsObject ) { - return toString( [nsObject description] ); - } +std::string StringMaker<NSString const *>::operator()(NSString const * const& nsstring) { + if (!nsstring) + return "nil"; + return "@" + toString([nsstring UTF8String]); +} +std::string StringMaker<NSString * CATCH_ARC_STRONG>::operator()(NSString * CATCH_ARC_STRONG const& nsstring) { + if (!nsstring) + return "nil"; + return "@" + toString([nsstring UTF8Str |