Last active
February 18, 2023 14:27
-
-
Save cmaglie/5883185 to your computer and use it in GitHub Desktop.
StringStream class for Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _STRING_STREAM_H_INCLUDED_ | |
#define _STRING_STREAM_H_INCLUDED_ | |
#include <Stream.h> | |
class StringStream : public Stream | |
{ | |
public: | |
StringStream(const 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; }; | |
private: | |
String &string; | |
int length; | |
int position; | |
}; | |
#endif // _STRING_STREAM_H_INCLUDED_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
would it be possible to achieve some thing like this:
tried it gives an error,
how do I achieve the above ?