📄 lineread.h
字号:
// lineread.h// module to buffer a stream input source to improve the cost// of partitioning that input source into lines during// online reading, such as from sockets or pipes// it may be possible to generalize parts of this, but something// really useful like an arbirary EOL test isn't possible// without major restructuring, due to handling of pathological// cases like EOL straddling a buffer boundary// copyright SafeTP Development Group, Inc., 2000 Terms of use are as specified in license.txt#ifndef __LINEREAD_H#define __LINEREAD_H#include "typ.h" // bool#include "str.h" // stringclass StreamInputSource;class StreamLineReader {private: // types enum { DEFAULT_BUFLEN = 1024, // just some value ENDPOST_VALUE = 0xBB, // mostly arbitrary CR = '\r', LF = '\n', // separator components };private: // data // stream source StreamInputSource &source; bool eof; // character buffer for large-length reads char *buffer; int bufferLen; // active area of buffer; start is next character // to return to user, end is next byte of buffer // to fill from source char *start, *end; // invariants: // buffer != NULL // (byte)buffer[bufferLen] == ENDPOST_VALUE // bufferLen > 0 // 0 <= (start-buffer) <= bufferLen // (start-buffer) <= (end-buffer) <= bufferLenprivate: // xassert that the invariants are true void selfCheck() const; // read from source int fillBuffer();public: StreamLineReader(StreamInputSource &src, int buflen = DEFAULT_BUFLEN); ~StreamLineReader(); // (blocking) read the next string from the input source // returns false (and leaves 's' unchanged) on EOF; // does NOT return the CRLF in the string; will throw an // exception iff source stream does bool getNextLine(string &s); // (nonblocking) does the buffer contain unprocessed data? bool hasUnprocessedData() const;};#endif // __LINEREAD_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -