9namespace string_functions {
11static int itoa(
int value,
char *sp,
int radix) {
17 int sign = (radix == 10 && value < 0);
23 while (v || tp == tmp) {
25 v = radix ? v / radix : 0;
45static float atoff(
const char *str,
size_t len) {
48 float fraction = 0.0f;
60 while (pos < len && (str[pos] ==
' ' || str[pos] ==
'\t' || str[pos] ==
'\n' || str[pos] ==
'\r' || str[pos] ==
'\f' || str[pos] ==
'\v')) {
65 if (pos < len && str[pos] ==
'-') {
68 }
else if (pos < len && str[pos] ==
'+') {
74 if (str[pos] >=
'0' && str[pos] <=
'9') {
77 fraction += (str[pos] -
'0') / divisor;
79 result = result * 10.0f + (str[pos] -
'0');
81 }
else if (str[pos] ==
'.' && !isFractional) {
91 result = result + fraction;
99void StringFormatter::append(int32_t val, StrN<64> *dst) {
101 string_functions::itoa(val, buf, 10);
102 dst->write(buf, strlen(buf));
104StringHolder::StringHolder(
const char *str) {
105 mLength = strlen(str);
106 mCapacity = mLength + 1;
107 mData =
new char[mCapacity];
108 memcpy(mData, str, mLength);
109 mData[mLength] =
'\0';
111StringHolder::StringHolder(
size_t length) {
112 mData = (
char *)malloc(length + 1);
115 mData[mLength] =
'\0';
123StringHolder::StringHolder(
const char *str,
size_t length) {
124 mData = (
char *)malloc(length + 1);
127 memcpy(mData, str, mLength);
128 mData[mLength] =
'\0';
135StringHolder::~StringHolder() {
139void StringHolder::grow(
size_t newLength) {
140 if (newLength <= mCapacity) {
145 char *newData = (
char *)realloc(mData, newLength + 1);
149 mCapacity = newLength;
150 mData[mLength] =
'\0';
153 char *newData = (
char *)malloc(newLength + 1);
155 memcpy(newData, mData, mLength + 1);
166float StringFormatter::parseFloat(
const char *str,
size_t len) {
167 return string_functions::atoff(str, len);
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.