13#ifndef FASTLED_STR_INLINED_SIZE
14#define FASTLED_STR_INLINED_SIZE 64
27template <
typename T>
struct rect;
28template <
typename T>
struct vec2;
29template <
typename T>
class Slice;
33template <
size_t N>
class StrN;
35template <
typename T>
struct Hash;
37template <
typename T>
struct EqualTo;
39template <
typename Key,
typename Hash,
typename KeyEqual>
class HashSet;
67 return c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'\r';
69 static float parseFloat(
const char *str,
size_t len);
70 static bool isDigit(
char c) {
return c >=
'0' && c <=
'9'; }
84 void grow(
size_t newLength);
90 bool copy(
const char *str,
size_t len) {
94 memcpy(
mData, str, len);
106template <
size_t SIZE = 64>
class StrN {
119 size_t len = strlen(str);
121 if (len + 1 <= SIZE) {
130 size_t len = strlen(str);
132 if (len + 1 <= SIZE) {
146 template <
int N>
StrN(
const char (&str)[N]) {
171 void copy(
const char *str,
size_t len) {
173 if (len + 1 <= SIZE) {
177 mHeapData = StringHolderPtr::New(str, len);
182 size_t len = other.
size();
183 if (len + 1 <= SIZE) {
198 size_t write(
const uint8_t *data,
size_t n) {
199 const char *str =
reinterpret_cast<const char *
>(data);
200 return write(str, n);
203 size_t write(
const char *str,
size_t n) {
207 size_t grow_length =
MAX(3, newLen * 3 / 2);
215 if (newLen + 1 <= SIZE) {
222 StringHolderPtr newData = StringHolderPtr::New(newLen);
225 memcpy(newData->data() +
mLength, str, n);
226 newData->data()[newLen] =
'\0';
237 const char *str =
reinterpret_cast<const char *
>(&c);
238 return write(str, 1);
282 static char dummy =
'\0';
290 static char dummy =
'\0';
293 return c_str()[index];
315 if (newCapacity + 1 <= SIZE) {
327 StringHolderPtr newData = StringHolderPtr::New(newCapacity);
331 newData->data()[
mLength] =
'\0';
336 void clear(
bool freeMemory =
false) {
343 int16_t
find(
const char &value)
const {
344 for (
size_t i = 0; i <
mLength; ++i) {
345 if (
c_str()[i] == value) {
388class Str :
public StrN<FASTLED_STR_INLINED_SIZE> {
391 Str(
const char *str) :
StrN<FASTLED_STR_INLINED_SIZE>(str) {}
392 Str(
const Str &other) :
StrN<FASTLED_STR_INLINED_SIZE>(other) {}
438 template <typename T, typename = fl::enable_if_t<fl::is_integral<T>::value>>
446 for (
size_t i = 0; i < slice.
size(); ++i) {
462 template <
typename T,
size_t N>
470 write(str, strlen(str));
479 const char *str =
reinterpret_cast<const char *
>(&c);
532 template <
typename T,
size_t N>
558 template <
typename Key,
typename Hash,
typename KeyEqual>
561 for (
auto it = set.
begin(); it != set.
end(); ++it) {
562 if (it != set.
begin()) {
constexpr size_t size() const
virtual int ref_count() const
static void compileTimeAssertions()
Str & append(const uint32_t &val)
Str & append(const Slice< T > &slice)
Str & append(const int8_t &c)
Str & append(const fl::FixedVector< T, N > &vec)
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)
Str & append(const fl::InlinedVector< T, N > &vec)
Str & append(const fl::HeapVector< T > &vec)
bool operator!=(const Str &other) const
Str & append(const bool &val)
Str & append(const float &_val)
bool operator<(const Str &other) const
Str(const StrN< M > &other)
Str & append(const T &val)
Str & append(const uint16_t &val)
Str & append(const int32_t &c)
Str & operator+=(const T &val)
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 StrN &str)
Str & append(const HashSet< Key, Hash, KeyEqual > &set)
Str & append(const vec2< T > &pt)
const char * data() const
Str & operator=(const Str &other)
Str & append(const double &val)
Str & append(const rect< T > &rect)
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_NAMESPACE_END
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
static FASTLED_NAMESPACE_BEGIN uint8_t const p[]
#define FASTLED_SMART_PTR(type)
Representation of an RGB pixel (Red, Green, Blue)