diff --git a/src/common/mm_io.cpp b/src/common/mm_io.cpp index 047cb5e4e..1829ddbf5 100644 --- a/src/common/mm_io.cpp +++ b/src/common/mm_io.cpp @@ -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 diff --git a/src/common/mm_io.h b/src/common/mm_io.h index b8ec6441b..176a1f119 100644 --- a/src/common/mm_io.h +++ b/src/common/mm_io.h @@ -30,7 +30,7 @@ typedef std::shared_ptr 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 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);