1 /*
2    mkvmerge -- utility for splicing together matroska files
3    from component media subtypes
4 
5    Distributed under the GPL v2
6    see the file COPYING for details
7    or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
8 
9    IO callback class definitions
10 
11    Written by Moritz Bunkus <moritz@bunkus.org>.
12 */
13 
14 #pragma once
15 
16 #include "common/common_pch.h"
17 
18 class mm_text_io_private_c;
19 class mm_text_io_c: public mm_proxy_io_c {
20 protected:
21   MTX_DECLARE_PRIVATE(mm_text_io_private_c)
22 
23   explicit mm_text_io_c(mm_text_io_private_c &p);
24 
25 public:
26   mm_text_io_c(mm_io_cptr const &in);
27 
28   virtual void setFilePointer(int64_t offset, libebml::seek_mode mode=libebml::seek_beginning) override;
29   virtual std::string getline(std::optional<std::size_t> max_chars = std::nullopt) override;
30   virtual std::string read_next_codepoint();
31   virtual byte_order_mark_e get_byte_order_mark() const;
32   virtual unsigned int get_byte_order_length() const;
33   virtual void set_byte_order_mark(byte_order_mark_e byte_order_mark);
34   virtual std::optional<std::string> get_encoding() const;
35 
36 protected:
37   virtual void detect_eol_style();
38 
39 public:
40   static bool has_byte_order_marker(const std::string &string);
41   static bool detect_byte_order_marker(const unsigned char *buffer, unsigned int size, byte_order_mark_e &byte_order_mark, unsigned int &bom_length);
42   static std::optional<std::string> get_encoding(byte_order_mark_e byte_order_mark);
43 };
44