#pragma once #include #include #include #include "sedpp/Options.h" namespace sedpp { // A loaded input record is sed's starting pattern space for one cycle. The // delimiter bit is carried separately so files without a trailing newline remain // distinguishable all the way to output. struct Record { std::string text; std::string fileName; bool hadDelimiter = false; bool lastInFile = false; bool lastOverall = false; std::uint64_t lineNumber = 0; std::uint64_t fileLineNumber = 0; }; // Reads stdin or input files eagerly into records. Eager loading simplifies GNU // sed's $ address and in-place rewrite behavior, both of which need to know the // last record before the runner starts emitting final output. class InputLoader { public: explicit InputLoader(const Options &options); [[nodiscard]] std::vector loadAll() const; [[nodiscard]] std::vector loadFile(const std::string &fileName) const; private: [[nodiscard]] std::vector splitBuffer(const std::string &buffer, const std::string &fileName, std::uint64_t &globalLine) const; const Options &options_; }; } // namespace sedpp