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);
89 int rc = readData(xsink, buffer,
QORE_MIN(limit, STREAMREADER_BUFFER_SIZE),
false);
99 return b->
empty() ? 0 : b.release();
109 return q_read_string(xsink, size,
enc, std::bind(&StreamReader::readData,
this, _3, _1, _2,
false));
122 return readLineEol(&nl, trim, xsink);
125 return eol ? readLineEol(eol, trim, xsink) :
readLine(trim, xsink);
140 int64 rc = readData(xsink, &c, 1,
false);
145 return str->empty() ? 0 : q_remove_bom_utf16(str.release(),
enc);
150 if ((**eolstr)[eolpos] == c) {
152 if (eolpos == eolstr->size()) {
154 str->terminate(str->size() - eolpos);
155 return q_remove_bom_utf16(str.release(),
enc);
160 for (
size_t i = eolpos; i; --i) {
163 if (!memcmp(eolstr->c_str(), str->c_str() + str->size() - i, i)) {
181 int64 rc = readData(xsink, &c, 1,
false);
185 return str->empty() ? 0 : str.release();
191 return str.release();
192 }
else if (c ==
'\r') {
195 int64 p = peek(xsink);
199 readData(xsink, &c, 1);
201 str->concat((
char)p);
203 return str.release();
211 if (readData(xsink, &i, 1) < 0)
218 if (readData(xsink, &i, 2) < 0)
226 if (readData(xsink, &i, 4) < 0)
234 if (readData(xsink, &i, 8) < 0)
242 if (readData(xsink, &i, 2) < 0)
250 if (readData(xsink, &i, 4) < 0)
258 if (readData(xsink, &i, 8) < 0)
266 if (readData(xsink, &i, 1) < 0)
272 unsigned short i = 0;
273 if (readData(xsink, &i, 2) < 0)
281 if (readData(xsink, &i, 4) < 0)
288 unsigned short i = 0;
289 if (readData(xsink, &i, 2) < 0)
297 if (readData(xsink, &i, 4) < 0)
309 int64 rc = peek(xsink);
313 xsink->
raiseException(
"END-OF-STREAM-ERROR",
"there is not enough data available in the stream; 1 byte was requested, and 0 were read");
335 return readData(xsink, dest, limit, require_all);
338 DLLLOCAL
virtual const char* getName()
const {
return "StreamReader"; }
342 static const int STREAMREADER_BUFFER_SIZE = 4096;
362 char* destPtr =
static_cast<char*
>(dest);
371 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);
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
#define QORE_MIN(a, b)
macro to return the minimum of 2 numbers
Definition: QoreLib.h:547
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:44
holds arbitrary binary data
Definition: BinaryNode.h:41
DLLEXPORT void append(const void *nptr, size_t size)
resizes the object and appends a copy of the data passed to the object
DLLEXPORT bool empty() const
returns true if empty
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
defines a Qore-language class
Definition: QoreClass.h:239
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
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
Private data for the Qore::StreamReader class.
Definition: StreamReader.h:45
virtual DLLLOCAL qore_offset_t read(ExceptionSink *xsink, void *dest, size_t limit, bool require_all=true)
Read data until a limit.
Definition: StreamReader.h:334
DLLLOCAL BinaryNode * readBinary(int64 limit, ExceptionSink *xsink)
Read binary data from the stream.
Definition: StreamReader.h:73
const QoreEncoding * enc
Encoding of the source input stream.
Definition: StreamReader.h:348
DLLLOCAL QoreStringNode * readString(int64 size, ExceptionSink *xsink)
Read string data from the stream.
Definition: StreamReader.h:108
ReferenceHolder< InputStream > in
Source input stream.
Definition: StreamReader.h:345
DLLLOCAL QoreStringNode * readLine(const QoreStringNode *eol, bool trim, ExceptionSink *xsink)
Read one line.
Definition: StreamReader.h:119
int64 peekCheck(ExceptionSink *xsink)
Peeks the next byte from the input stream.
Definition: StreamReader.h:308
use this class to manage strings where the character encoding must be specified and may be different ...
Definition: QoreString.h:1104
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:79
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
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