mm_io_c: provide function for checking if BOM has been written

This commit is contained in:
Moritz Bunkus 2014-03-10 19:43:38 +01:00
parent 9f1e60fe67
commit af47ad602b
2 changed files with 13 additions and 3 deletions

View File

@ -554,7 +554,7 @@ mm_io_c::write_bom(const std::string &charset) {
const unsigned char *bom;
unsigned int bom_len;
if (charset.empty())
if (m_bom_written || charset.empty())
return false;
if ((charset =="UTF-8") || (charset =="UTF8")) {
@ -577,7 +577,15 @@ mm_io_c::write_bom(const std::string &charset) {
setFilePointer(0, seek_beginning);
return (write(bom, bom_len) == bom_len);
m_bom_written = write(bom, bom_len) == bom_len;
return m_bom_written;
}
bool
mm_io_c::bom_written()
const {
return m_bom_written;
}
int64_t

View File

@ -30,7 +30,7 @@ typedef std::shared_ptr<charset_converter_c> charset_converter_cptr;
class mm_io_c: public IOCallback {
protected:
bool m_dos_style_newlines;
bool m_dos_style_newlines, m_bom_written;
std::stack<int64_t> m_positions;
int64_t m_current_position, m_cached_size;
charset_converter_cptr m_string_output_converter;
@ -38,6 +38,7 @@ protected:
public:
mm_io_c()
: m_dos_style_newlines(false)
, m_bom_written{}
, m_current_position(0)
, m_cached_size(-1)
{
@ -91,6 +92,7 @@ public:
return puts(format.str());
}
virtual bool write_bom(const std::string &charset);
virtual bool bom_written() const;
virtual int getch();
virtual void save_pos(int64_t new_pos = -1);