mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-04-25 15:57:21 +00:00
38 lines
753 B
C++
38 lines
753 B
C++
#ifndef _STRING_STREAM_H_
|
|
#define _STRING_STREAM_H_
|
|
|
|
#include <Stream.h>
|
|
|
|
class StringStream : public Stream {
|
|
public:
|
|
StringStream(String & s) : string(s), position(0)
|
|
{}
|
|
|
|
// Stream methods
|
|
virtual int available()
|
|
{
|
|
return string.length() - position;
|
|
}
|
|
virtual int read()
|
|
{
|
|
return position < string.length() ? string[position++] : -1;
|
|
}
|
|
virtual int peek()
|
|
{
|
|
return position < string.length() ? string[position] : -1;
|
|
}
|
|
virtual void flush(){};
|
|
// Print methods
|
|
virtual size_t write(uint8_t c)
|
|
{
|
|
string += (char)c;
|
|
return 1;
|
|
};
|
|
|
|
private:
|
|
String & string;
|
|
unsigned int length;
|
|
unsigned int position;
|
|
};
|
|
|
|
#endif // _STRING_STREAM_H_
|