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(
int val, StrN<64> *dst) {
101 string_functions::itoa(val, buf, 10);
102 dst->write(buf, strlen(buf));
105StringHolder::StringHolder(
const char *str) {
106 mLength = strlen(str);
107 mData = (
char *)malloc(mLength + 1);
109 memcpy(mData, str, mLength + 1);
116StringHolder::StringHolder(
size_t length) {
117 mData = (
char *)malloc(length + 1);
120 mData[mLength] =
'\0';
128StringHolder::StringHolder(
const char *str,
size_t length) {
129 mData = (
char *)malloc(length + 1);
132 memcpy(mData, str, mLength);
133 mData[mLength] =
'\0';
140StringHolder::~StringHolder() {
144void StringHolder::grow(
size_t newLength) {
145 if (newLength <= mCapacity) {
150 char *newData = (
char *)realloc(mData, newLength + 1);
154 mCapacity = newLength;
155 mData[mLength] =
'\0';
158 char *newData = (
char *)malloc(newLength + 1);
160 memcpy(newData, mData, mLength + 1);
171float StringFormatter::parseFloat(
const char *str,
size_t len) {
172 return string_functions::atoff(str, len);
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.