#ifndef UIO_HH #define UIO_HH #include "io.hh" // IWYU pragma: export #include #include #include namespace u { enum class ReaderInputFormat { UTF8, UTF16_BE, UTF16_LE, DETECT, }; struct ReaderConfig { // If false (default), invalid data is replaced with U+FFFD bool strict{false}; // Input format ReaderInputFormat input{ReaderInputFormat::DETECT}; // If true (default), any BOM found at start of stream will be skipped bool skip_bom{true}; }; } // namespace u8 namespace u8 { class Reader : public io::Reader { public: using io::Reader::read; using io::Reader::repeat_read; [[nodiscard]] std::expected read( std::string& data, size_t max); [[nodiscard]] std::expected repeat_read( std::string& data, size_t max); }; [[nodiscard]] std::unique_ptr open( std::unique_ptr reader, u::ReaderConfig config = {}); [[nodiscard]] std::expected, io::OpenError> open( const std::string& file_path, u::ReaderConfig config = {}); [[nodiscard]] std::expected, io::OpenError> openat( int dirfd, const std::string& file_path, u::ReaderConfig config = {}); } // namespace u8 namespace u16 { class Reader : public io::Reader { public: using io::Reader::read; using io::Reader::repeat_read; [[nodiscard]] std::expected read( std::u16string& data, size_t max); [[nodiscard]] std::expected repeat_read( std::u16string& data, size_t max); }; [[nodiscard]] std::unique_ptr open( std::unique_ptr reader, u::ReaderConfig config = {}); [[nodiscard]] std::expected, io::OpenError> open( const std::string& file_path, u::ReaderConfig config = {}); [[nodiscard]] std::expected, io::OpenError> openat( int dirfd, const std::string& file_path, u::ReaderConfig config = {}); } // namespace u16 #endif // UIO_HH