FastLED 3.10.6
Loading...
Searching...
No Matches

◆ strtoul()

unsigned long fl::strtoul ( const char * str,
char ** endptr,
int base )

Definition at line 160 of file cstdlib.cpp.hpp.

160 {
161 if (!str) {
162 if (endptr) {
163 *endptr = const_cast<char*>(str);
164 }
165 return 0;
166 }
167
168 const char* p = str;
169 unsigned long result = 0;
170
171 // Skip leading whitespace
172 while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\f' || *p == '\v') {
173 p++;
174 }
175
176 // Handle optional + sign (ignore - for unsigned)
177 if (*p == '+') {
178 p++;
179 } else if (*p == '-') {
180 // Negative values wrap around for unsigned
181 p++;
182 }
183
184 // Auto-detect base if base is 0
185 if (base == 0) {
186 if (*p == '0') {
187 if (*(p + 1) == 'x' || *(p + 1) == 'X') {
188 base = 16;
189 p += 2;
190 } else {
191 base = 8;
192 p++;
193 }
194 } else {
195 base = 10;
196 }
197 } else if (base == 16) {
198 // Skip optional 0x/0X prefix for base 16
199 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) {
200 p += 2;
201 }
202 }
203
204 // Validate base
205 if (base < 2 || base > 36) {
206 if (endptr) {
207 *endptr = const_cast<char*>(str);
208 }
209 return 0;
210 }
211
212 // Parse digits
213 const char* start = p;
214 while (*p && isDigitInBase(*p, base)) {
215 result = result * base + charToDigit(*p);
216 p++;
217 }
218
219 // Set endptr to point to first invalid character
220 if (endptr) {
221 if (p == start) {
222 // No digits parsed
223 *endptr = const_cast<char*>(str);
224 } else {
225 *endptr = const_cast<char*>(p);
226 }
227 }
228
229 return result;
230}
static int charToDigit(char c)
static bool isDigitInBase(char c, int base)
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References charToDigit(), and isDigitInBase().

Referenced by fl::net::http::ChunkedReader::parseChunkSize().

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