#pragma once #include #include #include #include namespace roro::gemini { // A page's text, kept as lines in 4 KB chunks: no large contiguous block (with IRC connected the // largest free block is about 31 KB) and no copy when it grows. About 4 bytes per line on top of // the text itself. Bytes are fed as they arrive; lines end at LF, a CR before it is dropped. class TextBuffer { public: static constexpr size_t kChunk = 4096; void append(const char* data, size_t len); void finish(); // the last line, if it has no line end size_t lineCount() const { return lines_.size(); } std::string line(size_t i) const; size_t bytes() const { return bytes_; } void clear(); private: struct Ref { uint16_t chunk; uint16_t offset; uint16_t length; }; void endLine(); std::vector chunks_; std::vector lines_; std::string partial_; // the line being received size_t bytes_ = 0; }; } // namespace roro::gemini