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:
Martin Hořeňovský 2021-03-25 19:30:59 +01:00
parent 2c269eb633
commit e50e10ef8f
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 4 additions and 5 deletions

View File

@ -74,7 +74,7 @@ namespace Detail {
class FileStream : public IStream {
mutable std::ofstream m_ofs;
public:
FileStream( StringRef filename ) {
FileStream( std::string const& filename ) {
m_ofs.open( filename.c_str() );
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() )
return new Detail::CoutStream();
else if( filename[0] == '%' ) {

View File

@ -13,6 +13,7 @@
#include <iosfwd>
#include <cstddef>
#include <ostream>
#include <string>
namespace Catch {
@ -20,14 +21,12 @@ namespace Catch {
std::ostream& cerr();
std::ostream& clog();
class StringRef;
struct IStream {
virtual ~IStream();
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 {
std::size_t m_index;