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

◆ parse_u32()

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

Definition at line 82 of file istream.cpp.hpp.

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

References fl::FL_NO_EXCEPT, isDigit(), isSpace(), parse_u32(), and fl::type_rank< T >::value.

Referenced by parse_u32().

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