12#ifndef FASTLED_STR_INLINED_SIZE
13#define FASTLED_STR_INLINED_SIZE 64
18template <
size_t N>
class StrN;
41 static bool isSpace(
char c) {
return c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'\r'; }
42 static float parseFloat(
const char *str,
size_t len);
43 static bool isDigit(
char c) {
return c >=
'0' && c <=
'9'; }
56 void grow(
size_t newLength);
62 bool copy(
const char *str,
size_t len) {
66 memcpy(
mData, str, len);
79template <
size_t SIZE = 64>
class StrN {
92 size_t len = strlen(str);
94 if (len + 1 <= SIZE) {
103 size_t len = strlen(str);
105 if (len + 1 <= SIZE) {
119 template<
int N>
StrN(
const char (&str)[N]) {
144 void copy(
const char* str,
size_t len) {
146 if (len + 1 <= SIZE) {
150 mHeapData = StringHolderPtr::New(str, len);
155 size_t len = other.
size();
156 if (len + 1 <= SIZE) {
174 size_t write(
const uint8_t *data,
size_t n) {
175 const char *str =
reinterpret_cast<const char *
>(data);
176 return write(str, n);
179 size_t write(
const char *str,
size_t n) {
183 size_t grow_length =
MAX(3, newLen * 3 / 2);
191 if (newLen + 1 <= SIZE) {
198 StringHolderPtr newData = StringHolderPtr::New(newLen);
201 memcpy(newData->data() +
mLength, str, n);
202 newData->data()[newLen] =
'\0';
213 const char *str =
reinterpret_cast<const char *
>(&c);
214 return write(str, 1);
257 static char dummy =
'\0';
265 static char dummy =
'\0';
268 return c_str()[index];
291 if (newCapacity + 1 <= SIZE) {
301 StringHolderPtr newData = StringHolderPtr::New(newCapacity);
305 newData->data()[
mLength] =
'\0';
310 void clear(
bool freeMemory =
false) {
319 int16_t
find(
const char &value)
const {
320 for (
size_t i = 0; i <
mLength; ++i) {
321 if (
c_str()[i] == value) {
368class Str :
public StrN<FASTLED_STR_INLINED_SIZE> {
413 const char* str =
reinterpret_cast<const char*
>(&c);
414 write(str, 1);
return *
this;
423 int32_t i =
static_cast<int32_t
>(val * 100);
433 return append(
float(val));
virtual int ref_count() const
Str & append(const uint32_t &val)
Str & append(const int8_t &c)
bool operator==(const Str &other) const
Str & append(const uint8_t &c)
Str & operator+=(const Str &other)
Str & append(const char *str, size_t len)
bool operator!=(const Str &other) const
bool operator<(const Str &other) const
Str(const StrN< M > &other)
Str & append(const uint16_t &val)
Str & append(const int32_t &c)
bool operator>(const Str &other) const
Str & append(const char *str)
Str & append(const int16_t &val)
bool operator<=(const Str &other) const
bool operator>=(const Str &other) const
Str & append(const float &val)
Str & append(const StrN &str)
Str & operator=(const Str &other)
Str & append(const double &val)
StrN & operator=(const StrN &other)
StrN & operator=(const StrN< M > &other)
StrN substring(size_t start, size_t end) const
void copy(const StrN< M > &other)
bool operator<(const StrN &other) const
char & operator[](size_t index)
StrN & operator=(const char(&str)[N])
size_t write(const uint8_t *data, size_t n)
void copy(const char *str, size_t len)
size_t write(const uint16_t &n)
size_t write(const int8_t val)
int16_t find(const char &value) const
bool operator!=(const StrN &other) const
const char * c_str() const
void clear(bool freeMemory=false)
StringHolderPtr mHeapData
StrN(const char(&str)[N])
StrN(const StrN< M > &other)
const char & operator[](size_t index) const
void copy(const char *str)
size_t write(const int32_t &val)
size_t write(const uint32_t &val)
bool operator==(const StrN &other) const
void reserve(size_t newCapacity)
size_t write(const char *str, size_t n)
bool operator<(const StrN< M > &other) const
StringHolder(const StringHolder &other)=delete
bool hasCapacity(size_t newLength) const
bool copy(const char *str, size_t len)
StringHolder(const char *str)
const char * data() const
StringHolder & operator=(const StringHolder &other)=delete
void grow(size_t newLength)
#define FASTLED_SMART_PTR(type)
#define FASTLED_STR_INLINED_SIZE
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.