Skip to content

Commit ff37d02

Browse files
committed
added StdCharBufStream which reads from a buffer
1 parent 8e684a0 commit ff37d02

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

simplecpp.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,42 @@ class StdIStream : public simplecpp::TokenList::Stream {
384384
std::istream &istr;
385385
};
386386

387+
class StdCharBufStream : public simplecpp::TokenList::Stream {
388+
public:
389+
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
390+
StdCharBufStream(const unsigned char* str, std::size_t size)
391+
: str(str)
392+
, size(size)
393+
, pos(0)
394+
, lastStatus(0)
395+
{
396+
init();
397+
}
398+
399+
virtual int get() OVERRIDE {
400+
if (pos >= size)
401+
return lastStatus = EOF;
402+
return str[pos++];
403+
}
404+
virtual int peek() OVERRIDE {
405+
if (pos >= size)
406+
return lastStatus = EOF;
407+
return str[pos];
408+
}
409+
virtual void unget() OVERRIDE {
410+
--pos;
411+
}
412+
virtual bool good() OVERRIDE {
413+
return lastStatus != EOF;
414+
}
415+
416+
private:
417+
const unsigned char *str;
418+
const std::size_t size;
419+
std::size_t pos;
420+
int lastStatus;
421+
};
422+
387423
class FileStream : public simplecpp::TokenList::Stream {
388424
public:
389425
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members

0 commit comments

Comments
 (0)