32 #ifndef _QORE_STREAMREADER_H 33 #define _QORE_STREAMREADER_H 37 #include "qore/qore_bitopts.h" 38 #include "qore/InputStream.h" 39 #include "qore/intern/StringReaderHelper.h" 42 DLLLOCAL
extern QoreClass* QC_STREAMREADER;
59 DLLLOCAL
const InputStream* getInputStream()
const {
77 char buffer[STREAMREADER_BUFFER_SIZE];
80 int rc = readData(xsink, buffer, STREAMREADER_BUFFER_SIZE,
false);
90 int rc = readData(xsink, buffer,
QORE_MIN(limit, STREAMREADER_BUFFER_SIZE),
false);
100 return b->
empty() ? 0 : b.release();
110 return q_read_string(xsink, size,
enc, std::bind(&StreamReader::readData,
this, _3, _1, _2,
false));
123 return readLineEol(&nl, trim, xsink);
126 return eol ? readLineEol(eol, trim, xsink) :
readLine(trim, xsink);
141 int64 rc = readData(xsink, &c, 1,
false);
146 return str->empty() ? 0 : q_remove_bom_utf16(str.release(),
enc);
151 if ((**eolstr)[eolpos] == c) {
153 if (eolpos == eolstr->size()) {
155 str->terminate(str->size() - eolpos);
156 return q_remove_bom_utf16(str.release(),
enc);
162 for (
size_t i = eolpos; i; --i) {
165 if (!memcmp(eolstr->c_str(), str->c_str() + str->size() - i, i)) {
183 int64 rc = readData(xsink, &c, 1,
false);
187 return str->empty() ? 0 : str.release();
193 return str.release();
195 else if (c ==
'\r') {
198 int64 p = peek(xsink);
202 readData(xsink, &c, 1);
204 str->concat((
char)p);
206 return str.release();
214 if (readData(xsink, &i, 1) < 0)
221 if (readData(xsink, &i, 2) < 0)
229 if (readData(xsink, &i, 4) < 0)
237 if (readData(xsink, &i, 8) < 0)
245 if (readData(xsink, &i, 2) < 0)
253 if (readData(xsink, &i, 4) < 0)
261 if (readData(xsink, &i, 8) < 0)
269 if (readData(xsink, &i, 1) < 0)
275 unsigned short i = 0;
276 if (readData(xsink, &i, 2) < 0)
284 if (readData(xsink, &i, 4) < 0)
291 unsigned short i = 0;
292 if (readData(xsink, &i, 2) < 0)
300 if (readData(xsink, &i, 4) < 0)
312 int64 rc = peek(xsink);
316 xsink->
raiseException(
"END-OF-STREAM-ERROR",
"there is not enough data available in the stream; 1 byte was requested, and 0 were read");
338 return readData(xsink, dest, limit, require_all);
341 DLLLOCAL
virtual const char* getName()
const {
return "StreamReader"; }
345 static const int STREAMREADER_BUFFER_SIZE = 4096;
365 char* destPtr =
static_cast<char*
>(dest);
374 xsink->
raiseException(
"END-OF-STREAM-ERROR",
"there is not enough data available in the stream; " QSD
" bytes were requested, and " QSD
" were read", limit,
read);
396 #endif // _QORE_STREAMREADER_H defines string encoding functions in Qore
Definition: QoreEncoding.h:83
DLLEXPORT bool isAsciiCompat() const
returns true if the character encoding is backwards-compatible with ASCII
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:44
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
ReferenceHolder< InputStream > in
Source input stream.
Definition: StreamReader.h:348
DLLEXPORT bool empty() const
returns true if empty
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:73
virtual DLLLOCAL qore_offset_t read(ExceptionSink *xsink, void *dest, qore_size_t limit, bool require_all=true)
Read data until a limit.
Definition: StreamReader.h:337
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
DLLLOCAL QoreStringNode * readString(int64 size, ExceptionSink *xsink)
Read string data from the stream.
Definition: StreamReader.h:109
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT void concat(const QoreString *str, ExceptionSink *xsink)
concatenates a string and converts encodings if necessary
defines a Qore-language class
Definition: QoreClass.h:234
use this class to manage strings where the character encoding must be specified and may be different ...
Definition: QoreString.h:1013
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:79
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
DLLLOCAL QoreStringNode * readLine(const QoreStringNode *eol, bool trim, ExceptionSink *xsink)
Read one line.
Definition: StreamReader.h:120
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
#define QORE_MIN(a, b)
macro to return the minimum of 2 numbers
Definition: QoreLib.h:538
DLLLOCAL BinaryNode * readBinary(int64 limit, ExceptionSink *xsink)
Read binary data from the stream.
Definition: StreamReader.h:73
int64 peekCheck(ExceptionSink *xsink)
Peeks the next byte from the input stream.
Definition: StreamReader.h:311
const QoreEncoding * enc
Encoding of the source input stream.
Definition: StreamReader.h:351
Private data for the Qore::StreamReader class.
Definition: StreamReader.h:45
DLLEXPORT void append(const void *nptr, qore_size_t size)
resizes the object and appends a copy of the data passed to the object
holds arbitrary binary data
Definition: BinaryNode.h:41