F439_CPP_SPI_RA8875_TFT_LCD_03 1.0
STM32F439 SPI RA8875 7-inch TFT display demo built on the STM32_GFX and STM32_RA8875 libraries
Loading...
Searching...
No Matches
WString.h
Go to the documentation of this file.
1
15#ifndef STM32_WSTRING_H_
16#define STM32_WSTRING_H_
17
18#include <stdlib.h>
19#include <string.h>
20
22class String {
23public:
26 String(const char *s = "") : buf_(nullptr), len_(0) { assign(s); }
29 String(const String &o) : buf_(nullptr), len_(0) { assign(o.buf_); }
33 String &operator=(const String &o) {
34 if (this != &o)
35 assign(o.buf_);
36 return *this;
37 }
41 String &operator=(const char *s) {
42 assign(s);
43 return *this;
44 }
46 ~String() { free(buf_); }
47
49 const char *c_str() const { return buf_ ? buf_ : ""; }
51 unsigned int length() const { return len_; }
54 char operator[](unsigned int i) const { return (i < len_) ? buf_[i] : 0; }
55
56private:
57 void assign(const char *s) {
58 free(buf_);
59 buf_ = nullptr;
60 len_ = 0;
61 if (!s)
62 return;
63 len_ = (unsigned int)strlen(s);
64 buf_ = (char *)malloc(len_ + 1);
65 if (buf_)
66 memcpy(buf_, s, len_ + 1);
67 else
68 len_ = 0;
69 }
70 char *buf_;
71 unsigned int len_;
72};
73
74#endif // STM32_WSTRING_H_
Minimal Arduino-String stand-in (see file description).
Definition WString.h:22
String & operator=(const String &o)
Definition WString.h:33
String & operator=(const char *s)
Definition WString.h:41
char operator[](unsigned int i) const
Definition WString.h:54
String(const String &o)
Definition WString.h:29
const char * c_str() const
Definition WString.h:49
unsigned int length() const
Definition WString.h:51
~String()
Destructor frees the copy.
Definition WString.h:46
String(const char *s="")
Definition WString.h:26