59 lines
748 B
C
Raw Normal View History

2020-11-27 11:28:57 +01:00
#pragma once
2017-12-10 01:35:48 +01:00
//
// FILE: PrintString.h
// AUTHOR: Rob Tillaart
2022-11-22 17:02:48 +01:00
// VERSION: 0.2.3
2017-12-10 01:35:48 +01:00
// PURPOSE: Class that captures prints into a String
// DATE: 2017-12-09
2020-11-27 11:28:57 +01:00
// URL: https://github.com/RobTillaart/PrintString
2021-01-29 12:31:58 +01:00
2017-12-10 01:35:48 +01:00
2021-01-29 12:31:58 +01:00
#include "Arduino.h"
2017-12-10 01:35:48 +01:00
#include "Print.h"
2021-01-29 12:31:58 +01:00
2022-11-22 17:02:48 +01:00
#define PRINTSTRING_VERSION (F("0.2.3"))
2021-01-29 12:31:58 +01:00
2017-12-10 01:35:48 +01:00
class PrintString: public Print
{
public:
PrintString() {};
2021-11-14 17:19:48 +01:00
2017-12-10 01:35:48 +01:00
size_t write(uint8_t c)
{
2020-11-27 11:28:57 +01:00
buffer.concat(char(c));
2017-12-10 01:35:48 +01:00
return 1;
}
2021-11-14 17:19:48 +01:00
size_t write(uint8_t * str, uint8_t length)
{
buffer.concat((char*)str);
return length;
}
2020-11-27 11:28:57 +01:00
size_t size()
{
return buffer.length();
}
2021-11-14 17:19:48 +01:00
2017-12-10 01:35:48 +01:00
void clear()
{
buffer = "";
}
2021-11-14 17:19:48 +01:00
2017-12-10 01:35:48 +01:00
String getString() { return buffer; }
private:
String buffer;
};
2020-11-27 11:28:57 +01:00
2021-11-14 17:19:48 +01:00
2017-12-10 01:35:48 +01:00
// -- END OF FILE --
2021-11-14 17:19:48 +01:00