Arduino DLNA Server
Loading...
Searching...
No Matches
StrPrint.h
Go to the documentation of this file.
1#pragma once
2#include "Print.h"
3#include "Str.h"
4
5namespace tiny_dlna {
6
12class StrPrint : public Print {
13 public:
14 StrPrint(int incSize = 200) { inc_size = incSize; }
15 size_t write(uint8_t ch) override {
16 if (str.length() >= str.capacity() - 1) {
18 }
19 str.add((const char)ch);
20 return 1;
21 }
22
23 size_t write(const uint8_t* buffer, size_t size) override {
24 size_t result = 0;
25 for (int j = 0; j < size; j++) {
26 result += write(buffer[j]);
27 }
28 // expand encoded entities if desired
29 if (expand_encoded) {
30 str.replaceAll("&amp;", "&");
31 str.replaceAll("&lt;", "<");
32 str.replaceAll("&gt;", ">");
33 }
34
35 return result;
36 }
37
38 const char* c_str() { return str.c_str(); }
39
40 size_t length() { return str.length(); }
41
42 void reset() { str.reset(); }
43
44 void consume(int n) { str.remove(n); }
45
46 void setExpandEncoded(bool flag) { expand_encoded = flag; }
47
48 protected:
49 Str str{200};
51 bool expand_encoded = false;
52};
53
54} // namespace tiny_dlna
Print to a dynamic string.
Definition: StrPrint.h:12
const char * c_str()
Definition: StrPrint.h:38
size_t length()
Definition: StrPrint.h:40
size_t write(uint8_t ch) override
Definition: StrPrint.h:15
void reset()
Definition: StrPrint.h:42
size_t write(const uint8_t *buffer, size_t size) override
Definition: StrPrint.h:23
bool expand_encoded
Definition: StrPrint.h:51
void consume(int n)
Definition: StrPrint.h:44
void setExpandEncoded(bool flag)
Definition: StrPrint.h:46
int inc_size
Definition: StrPrint.h:50
Str str
Definition: StrPrint.h:49
StrPrint(int incSize=200)
Definition: StrPrint.h:14
virtual void add(int value)
adds a int value
Definition: StrView.h:129
virtual bool replaceAll(const char *toReplace, const char *replaced)
Replaces all instances of toReplace with replaced.
Definition: StrView.h:436
virtual int length()
Definition: StrView.h:380
String implementation which keeps the data on the heap. We grow the allocated memory only if the copy...
Definition: Str.h:22
const char * c_str()
provides the string value as const char*
Definition: Str.h:187
size_t capacity()
Definition: Str.h:81
void reset()
Definition: Str.h:190
void setCapacity(size_t newLen)
Definition: Str.h:83
void remove(int n)
removes the first n characters
Definition: Str.h:209
Definition: Allocator.h:6