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

◆ parseInt() [2/2]

int fl::parseInt ( const char * str,
fl::size len )

Parse an integer from a character buffer.

Parameters
strThe character buffer to parse
lenThe length of the buffer
Returns
The parsed integer value (0 if parsing fails)

Definition at line 253 of file charconv.cpp.hpp.

253 {
254 // Unsigned magnitude can represent abs(INT_MIN) without signed overflow.
255 unsigned int result = 0;
256 int sign = 1;
257 fl::size pos = 0;
258
259 // Handle empty input
260 if (len == 0) {
261 return 0;
262 }
263
264 // Skip leading whitespace
265 while (pos < len &&
266 (str[pos] == ' ' || str[pos] == '\t' || str[pos] == '\n' ||
267 str[pos] == '\r' || str[pos] == '\f' || str[pos] == '\v')) {
268 pos++;
269 }
270
271 // Handle optional sign
272 if (pos < len && str[pos] == '-') {
273 sign = -1;
274 pos++;
275 } else if (pos < len && str[pos] == '+') {
276 pos++;
277 }
278
279 // Parse digits
280 while (pos < len && str[pos] >= '0' && str[pos] <= '9') {
281 result = result * 10u + static_cast<unsigned int>(str[pos] - '0');
282 pos++;
283 }
284
285 return static_cast<int>(sign < 0 ? 0u - result : result);
286}
uint8_t pos
Definition Blur.ino:11
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
constexpr enable_if< is_fixed_point< T >::value, int >::type sign(T x) FL_NO_EXCEPT

References FL_NO_EXCEPT, pos, and sign().

Referenced by fl::HttpRequestParser::feed(), fl::HttpResponseParser::feed(), fl::anonymous_namespace{json.cpp.hpp}::JsonBuilder::on_token(), fl::int_conversion_visitor< IntType >::operator()(), fl::int_conversion_visitor< i64 >::operator()(), fl::anonymous_namespace{json.cpp.hpp}::JsonBuilder::parse_float_array(), fl::anonymous_namespace{json.cpp.hpp}::JsonBuilder::parse_int_array(), parseInt(), fl::HttpResponseParser::parseStatusLine(), and fl::anonymous_namespace{json.cpp.hpp}::JsonTokenizer::scan_array_lookahead().

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