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

◆ operator()() [6/15]

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

Definition at line 243 of file types.h.

243 {
244 // NEW INSTRUCTIONS: AUTO CONVERT STRING TO INT
245 // Try to parse the string as an integer using FastLED's StringFormatter
246 // Validate by checking if string contains only digits (and optional +/- sign)
247 bool isValidInt = true;
248 fl::size startPos = 0;
249
250 // Check for sign
251 if (str.length() > 0 && (str[0] == '+' || str[0] == '-')) {
252 startPos = 1;
253 }
254
255 // Check that all remaining characters are digits
256 for (fl::size i = startPos; i < str.length(); i++) {
257 if (!fl::isdigit(str[i])) {
258 isValidInt = false;
259 break;
260 }
261 }
262
263 // If it looks like a valid integer, try to parse it
264 if (isValidInt && str.length() > 0) {
265 int parsed = fl::parseInt(str.c_str(), str.length());
266 result = static_cast<IntType>(parsed);
267 }
268 }
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