Arduino DLNA Server
StrPrint.h
Go to the documentation of this file.
1 #include "Print.h"
2 #include "Str.h"
3 
4 namespace tiny_dlna {
5 
6 /***
7  * @brief Print to a dynamic string
8  * @author Phil Schatzmann
9  * @copyright GPLv3
10  */
11 class StrPrint : public Print {
12  public:
13  StrPrint(int incSize = 200) { inc_size = incSize; }
14  size_t write(uint8_t ch) override {
15  if (str.length() >= str.capacity() - 1) {
17  }
18  str.add((const char)ch);
19  return 1;
20  }
21 
22  size_t write(const uint8_t* buffer, size_t size) override {
23  size_t result = 0;
24  for (int j = 0; j < size; j++) {
25  result += write(buffer[j]);
26  }
27  return result;
28  }
29 
30  const char* c_str() { return str.c_str(); }
31 
32  size_t length() { return str.length(); }
33 
34  void reset() { str.reset(); }
35 
36  protected:
37  Str str{200};
38  int inc_size;
39 };
40 
41 } // namespace tiny_dlna
Definition: StrPrint.h:11
size_t length()
Definition: StrPrint.h:32
size_t write(uint8_t ch) override
Definition: StrPrint.h:14
void reset()
Definition: StrPrint.h:34
size_t write(const uint8_t *buffer, size_t size) override
Definition: StrPrint.h:22
const char * c_str()
Definition: StrPrint.h:30
int inc_size
Definition: StrPrint.h:38
Str str
Definition: StrPrint.h:37
StrPrint(int incSize=200)
Definition: StrPrint.h:13
virtual void add(int value)
adds a int value
Definition: StrView.h:130
virtual int length()
Definition: StrView.h:370
String implementation which keeps the data on the heap. We grow the allocated memory only if the copy...
Definition: Str.h:22
size_t capacity()
Definition: Str.h:82
void reset()
Definition: Str.h:191
void setCapacity(size_t newLen)
Definition: Str.h:84
const char * c_str()
provides the string value as const char*
Definition: Str.h:188
Definition: Allocator.h:6