roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
string_printer.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef ARDUINO
4#include <Print.h>
5#endif
6
7#include <stdarg.h>
8#include <stdio.h>
9
10#include <string>
11
12namespace roo_display {
13
14/// Prefer `roo_io::StringPrintf` in new code.
15std::string StringPrintf(const char* format, ...);
16
17/// Prefer `roo_io::StringVPrintf` in new code.
18std::string StringVPrintf(const char* format, va_list arg);
19
20#ifdef ARDUINO
21/// Utility that formats into a `std::string` via `Print`.
22class StringPrinter : public Print {
23 public:
24 const std::string& get() const& { return s_; }
25 const std::string get() && { return std::move(s_); }
26
27 size_t write(uint8_t c) override {
28 s_.append((const char*)(&c));
29 return 1;
30 }
31
32 size_t write(const uint8_t* buffer, size_t size) override {
33 s_.append((const char*)buffer, size);
34 return size;
35 }
36
37 private:
38 std::string s_;
39};
40#endif
41
42} // namespace roo_display
Defines 140 opaque HTML named colors.
std::string StringVPrintf(const char *format, va_list arg)
Prefer roo_io::StringVPrintf in new code.
std::string StringPrintf(const char *format,...)
Prefer roo_io::StringPrintf in new code.
#define const
Definition zconf.h:230