FastLED 3.9.15
Loading...
Searching...
No Matches

◆ atoff()

static float fl::string_functions::atoff ( const char * str,
fl::size len )
static

Definition at line 154 of file str.cpp.

154 {
155 float result = 0.0f; // The resulting number
156 float sign = 1.0f; // Positive or negative
157 float fraction = 0.0f; // Fractional part
158 float divisor = 1.0f; // Divisor for the fractional part
159 int isFractional = 0; // Whether the current part is fractional
160
161 fl::size pos = 0; // Current position in the string
162
163 // Handle empty input
164 if (len == 0) {
165 return 0.0f;
166 }
167
168 // Skip leading whitespace (manual check instead of isspace)
169 while (pos < len &&
170 (str[pos] == ' ' || str[pos] == '\t' || str[pos] == '\n' ||
171 str[pos] == '\r' || str[pos] == '\f' || str[pos] == '\v')) {
172 pos++;
173 }
174
175 // Handle optional sign
176 if (pos < len && str[pos] == '-') {
177 sign = -1.0f;
178 pos++;
179 } else if (pos < len && str[pos] == '+') {
180 pos++;
181 }
182
183 // Main parsing loop
184 while (pos < len) {
185 if (str[pos] >= '0' && str[pos] <= '9') {
186 if (isFractional) {
187 divisor *= 10.0f;
188 fraction += (str[pos] - '0') / divisor;
189 } else {
190 result = result * 10.0f + (str[pos] - '0');
191 }
192 } else if (str[pos] == '.' && !isFractional) {
193 isFractional = 1;
194 } else {
195 // Stop parsing at invalid characters
196 break;
197 }
198 pos++;
199 }
200
201 // Combine integer and fractional parts
202 result = result + fraction;
203
204 // Apply the sign
205 return sign * result;
206}
uint8_t pos
Definition Blur.ino:11
Result type for promise operations.

References atoff(), and pos.

Referenced by atoff(), and fl::StringFormatter::parseFloat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: