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

◆ parse_u32()

bool fl::anonymous_namespace{istream.cpp}::parse_u32 ( const char * str,
fl::u32 & result )

Definition at line 81 of file istream.cpp.

81 {
82 if (!str) return false;
83
84 // Skip leading whitespace
85 while (*str && isSpace(*str)) {
86 str++;
87 }
88
89 if (*str == '\0') return false;
90
91 // Optional '+' sign (no '-' for unsigned)
92 if (*str == '+') {
93 str++;
94 } else if (*str == '-') {
95 return false; // Negative not allowed for unsigned
96 }
97
98 if (*str == '\0' || !isDigit(*str)) return false;
99
100 fl::u32 value = 0;
101 const fl::u32 max_div_10 = 429496729U; // UINT32_MAX / 10
102 const fl::u32 max_mod_10 = 5U; // UINT32_MAX % 10
103
104 while (*str && isDigit(*str)) {
105 fl::u32 digit = *str - '0';
106
107 // Check for overflow
108 if (value > max_div_10 || (value == max_div_10 && digit > max_mod_10)) {
109 return false; // Overflow
110 }
111
112 value = value * 10 + digit;
113 str++;
114 }
115
116 // Check if we stopped at a non-digit character (should be end of string for valid parse)
117 if (*str != '\0') return false;
118
119 result = value;
120 return true;
121 }

References isDigit(), isSpace(), and parse_u32().

Referenced by parse_u32().

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