mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Replaced direct emitter writing with an accessor to a C-string
This commit is contained in:
@@ -15,8 +15,9 @@ namespace YAML
|
||||
Emitter();
|
||||
~Emitter();
|
||||
|
||||
bool WriteToStream(std::ostream& out) const;
|
||||
bool WriteToFile(const std::string& fileName) const;
|
||||
// output
|
||||
const char *c_str() const;
|
||||
unsigned size() const;
|
||||
|
||||
// state checking
|
||||
bool good() const;
|
||||
|
@@ -16,6 +16,7 @@ namespace YAML
|
||||
|
||||
unsigned row() const { return m_row; }
|
||||
unsigned col() const { return m_col; }
|
||||
unsigned pos() const { return m_pos; }
|
||||
|
||||
private:
|
||||
char *m_buffer;
|
||||
|
@@ -3,7 +3,6 @@
|
||||
#include "emitterutils.h"
|
||||
#include "indentation.h"
|
||||
#include "exceptions.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace YAML
|
||||
@@ -16,19 +15,14 @@ namespace YAML
|
||||
{
|
||||
}
|
||||
|
||||
bool Emitter::WriteToStream(std::ostream& out) const
|
||||
const char *Emitter::c_str() const
|
||||
{
|
||||
out << m_stream.str();
|
||||
return true;
|
||||
return m_stream.str();
|
||||
}
|
||||
|
||||
bool Emitter::WriteToFile(const std::string& fileName) const
|
||||
unsigned Emitter::size() const
|
||||
{
|
||||
std::ofstream fout(fileName.c_str());
|
||||
if(!fout)
|
||||
return false;
|
||||
|
||||
return WriteToStream(fout);
|
||||
return m_stream.pos();
|
||||
}
|
||||
|
||||
// state checking
|
||||
|
@@ -101,16 +101,15 @@ namespace Test
|
||||
YAML::Emitter out;
|
||||
std::string desiredOutput;
|
||||
test(out, desiredOutput);
|
||||
std::stringstream output;
|
||||
out.WriteToStream(output);
|
||||
std::string output = out.c_str();
|
||||
|
||||
if(output.str() == desiredOutput) {
|
||||
if(output == desiredOutput) {
|
||||
std::cout << "Test passed: " << name << "\n";
|
||||
} else {
|
||||
passed = false;
|
||||
std::cout << "Test failed: " << name << "\n";
|
||||
std::cout << "Output:\n";
|
||||
std::cout << output.str() << "<<<\n";
|
||||
std::cout << output << "<<<\n";
|
||||
std::cout << "Desired output:\n";
|
||||
std::cout << desiredOutput << "<<<\n";
|
||||
}
|
||||
|
Reference in New Issue
Block a user