mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-04 05:59:32 +01:00 
			
		
		
		
	Use std::string instead of StringRef as argument to the makeStream
This is done because `makeStream` was the only place using `StringRef::c_str()`, which is an error-prone and unsafe API that I want to remove.
This commit is contained in:
		@@ -74,7 +74,7 @@ namespace Detail {
 | 
				
			|||||||
        class FileStream : public IStream {
 | 
					        class FileStream : public IStream {
 | 
				
			||||||
            mutable std::ofstream m_ofs;
 | 
					            mutable std::ofstream m_ofs;
 | 
				
			||||||
        public:
 | 
					        public:
 | 
				
			||||||
            FileStream( StringRef filename ) {
 | 
					            FileStream( std::string const& filename ) {
 | 
				
			||||||
                m_ofs.open( filename.c_str() );
 | 
					                m_ofs.open( filename.c_str() );
 | 
				
			||||||
                CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" );
 | 
					                CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" );
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -121,7 +121,7 @@ namespace Detail {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    ///////////////////////////////////////////////////////////////////////////
 | 
					    ///////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto makeStream( StringRef const &filename ) -> IStream const* {
 | 
					    auto makeStream( std::string const& filename ) -> IStream const* {
 | 
				
			||||||
        if( filename.empty() )
 | 
					        if( filename.empty() )
 | 
				
			||||||
            return new Detail::CoutStream();
 | 
					            return new Detail::CoutStream();
 | 
				
			||||||
        else if( filename[0] == '%' ) {
 | 
					        else if( filename[0] == '%' ) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,7 @@
 | 
				
			|||||||
#include <iosfwd>
 | 
					#include <iosfwd>
 | 
				
			||||||
#include <cstddef>
 | 
					#include <cstddef>
 | 
				
			||||||
#include <ostream>
 | 
					#include <ostream>
 | 
				
			||||||
 | 
					#include <string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Catch {
 | 
					namespace Catch {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,14 +21,12 @@ namespace Catch {
 | 
				
			|||||||
    std::ostream& cerr();
 | 
					    std::ostream& cerr();
 | 
				
			||||||
    std::ostream& clog();
 | 
					    std::ostream& clog();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class StringRef;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    struct IStream {
 | 
					    struct IStream {
 | 
				
			||||||
        virtual ~IStream();
 | 
					        virtual ~IStream();
 | 
				
			||||||
        virtual std::ostream& stream() const = 0;
 | 
					        virtual std::ostream& stream() const = 0;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto makeStream( StringRef const &filename ) -> IStream const*;
 | 
					    auto makeStream( std::string const& filename ) -> IStream const*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class ReusableStringStream : Detail::NonCopyable {
 | 
					    class ReusableStringStream : Detail::NonCopyable {
 | 
				
			||||||
        std::size_t m_index;
 | 
					        std::size_t m_index;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user