FastLED 3.10.8
Loading...
Searching...
No Matches

◆ operator()() [7/15]

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

Definition at line 319 of file types.h.

319 {
320 // NEW INSTRUCTIONS: AUTO CONVERT STRING TO INT
321 // Try to parse the string as an integer using FastLED's StringFormatter
322 // Validate by checking if string contains only digits (and optional +/- sign)
323 bool isValidInt = true;
324 fl::size startPos = 0;
325
326 // Check for sign
327 if (str.length() > 0 && (str[0] == '+' || str[0] == '-')) {
328 startPos = 1;
329 }
330
331 // Check that all remaining characters are digits
332 for (fl::size i = startPos; i < str.length(); i++) {
333 if (!fl::isdigit(str[i])) {
334 isValidInt = false;
335 break;
336 }
337 }
338
339 // If it looks like a valid integer, try to parse it
340 if (isValidInt && str.length() > 0) {
341 int parsed = fl::parseInt(str.c_str(), str.length());
342 result = static_cast<i64>(parsed);
343 }
344 }
int parseInt(const char *str, fl::size len) FL_NO_EXCEPT
Parse an integer from a character buffer.
fl::optional< i64 > result
Definition types.h:279

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

+ Here is the call graph for this function: