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

◆ operator()() [4/9]

template<typename IntType = i64>
void fl::int_conversion_visitor< IntType >::operator() ( const fl::string & str)
inline

Definition at line 212 of file types.h.

212 {
213 // NEW INSTRUCTIONS: AUTO CONVERT STRING TO INT
214 // Try to parse the string as an integer using FastLED's StringFormatter
215 // Validate by checking if string contains only digits (and optional +/- sign)
216 bool isValidInt = true;
217 fl::size startPos = 0;
218
219 // Check for sign
220 if (str.length() > 0 && (str[0] == '+' || str[0] == '-')) {
221 startPos = 1;
222 }
223
224 // Check that all remaining characters are digits
225 for (fl::size i = startPos; i < str.length(); i++) {
226 if (!fl::isdigit(str[i])) {
227 isValidInt = false;
228 break;
229 }
230 }
231
232 // If it looks like a valid integer, try to parse it
233 if (isValidInt && str.length() > 0) {
234 int parsed = fl::parseInt(str.c_str(), str.length());
235 result = static_cast<IntType>(parsed);
236 }
237 }
int parseInt(const char *str, fl::size len)
Parse an integer from a character buffer.
fl::optional< IntType > result
Definition types.h:143

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

+ Here is the call graph for this function: