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

References 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: