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

◆ operator()() [7/15]

void fl::int_conversion_visitor< i64 >::operator() ( const fl::string & str)
inline

Definition at line 288 of file types.h.

288 {
289 // NEW INSTRUCTIONS: AUTO CONVERT STRING TO INT
290 // Try to parse the string as an integer using FastLED's StringFormatter
291 // Validate by checking if string contains only digits (and optional +/- sign)
292 bool isValidInt = true;
293 fl::size startPos = 0;
294
295 // Check for sign
296 if (str.length() > 0 && (str[0] == '+' || str[0] == '-')) {
297 startPos = 1;
298 }
299
300 // Check that all remaining characters are digits
301 for (fl::size i = startPos; i < str.length(); i++) {
302 if (!fl::isdigit(str[i])) {
303 isValidInt = false;
304 break;
305 }
306 }
307
308 // If it looks like a valid integer, try to parse it
309 if (isValidInt && str.length() > 0) {
310 int parsed = fl::parseInt(str.c_str(), str.length());
311 result = static_cast<i64>(parsed);
312 }
313 }
int parseInt(const char *str, fl::size len)
Parse an integer from a character buffer.
fl::optional< i64 > result
Definition types.h:248

References FL_NOEXCEPT, fl::isdigit(), fl::parseInt(), and result.

+ Here is the call graph for this function: