#pragma once #include #include #include #include #include #include "sedpp/Options.h" namespace sedpp { // Centralizes delimiter-aware writes. Most commands emit either pattern space // plus its original delimiter bit, or synthetic lines that always end in the // active delimiter. class Output { public: Output(const Options &options, std::ostream &stream); void write(const std::string &text); void writeDelimiter(bool hadDelimiter); void writeLine(const std::string &text); void writePattern(const std::string &pattern, bool hadDelimiter); void writeEscaped(const std::string &pattern, bool hadDelimiter, int width); void writeFile(const std::string &path, const std::string &text, bool hadDelimiter); private: // Pending delimiters defer the trailing separator for unterminated records // until another write proves that a separator is needed between outputs. void writePendingDelimiter(std::ostream &target, bool &pending); char delimiter() const; const Options &options_; std::ostream &stream_; bool pendingDelimiter_ = false; std::unordered_map pendingFileDelimiter_; std::unordered_set openedWriteFiles_; }; } // namespace sedpp