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

◆ parse_float_array()

template<typename T>
bool fl::anonymous_namespace{json.cpp.hpp}::JsonBuilder::parse_float_array ( const fl::span< const char > & span,
fl::vector< T > & out_vec )
inlineprivate

Definition at line 846 of file json.cpp.hpp.

846 {
847 const char* p = span.data();
848 const char* end = p + span.size();
849
850 while (p < end) {
851 // Skip whitespace
852 while (p < end && (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')) p++;
853 if (p >= end) break;
854
855 // Parse number
856 const char* num_start = p;
857 bool is_float = false;
858
859 if (*p == '-') p++;
860 while (p < end && *p >= '0' && *p <= '9') p++;
861
862 if (p < end && *p == '.') {
863 is_float = true;
864 p++;
865 while (p < end && *p >= '0' && *p <= '9') p++;
866 }
867
868 if (p < end && (*p == 'e' || *p == 'E')) {
869 is_float = true;
870 p++;
871 if (p < end && (*p == '+' || *p == '-')) p++;
872 while (p < end && *p >= '0' && *p <= '9') p++;
873 }
874
875 T val;
876 if (is_float) {
877#if FL_PLATFORM_HAS_LARGE_MEMORY
878 // Bit-twiddling parse -> IEEE 754 bit pattern -> bit-cast to float.
879 // The `static_cast<T>` from `float` is the caller's responsibility
880 // (e.g. T=float costs nothing; T=int pulls one __aeabi_f2iz at the
881 // call site, which we accept per the "user opts in" mandate).
882 const u32 bits = fl::ieee754_parse_decimal(num_start, p - num_start);
883 val = static_cast<T>(fl::bit_cast<float>(bits));
884#else
885 // Low-memory gate per FastLED #3082: float JSON literals in
886 // packed-array parse path saturate to zero. The integer-only
887 // RPC contract on LPC8xx / AVR never emits floats here.
888 val = static_cast<T>(0);
889#endif
890 } else {
891 val = static_cast<T>(fl::parseInt(num_start, p - num_start));
892 }
893 out_vec.push_back(val);
894
895 // Skip whitespace
896 while (p < end && (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')) p++;
897
898 // Skip comma
899 if (p < end && *p == ',') p++;
900 }
901
902 return true;
903 }
const T * data() const FL_NO_EXCEPT
Definition span.h:486
constexpr fl::size size() const FL_NO_EXCEPT
Definition span.h:483
void push_back(const T &value) FL_NO_EXCEPT
Definition vector.h:624
u32 ieee754_parse_decimal(const char *s, fl::size len, fl::size *consumed) FL_NO_EXCEPT
Parse a decimal floating-point number into IEEE 754 single-precision bits.
int parseInt(const char *str, fl::size len)
Parse an integer from a character buffer.
To bit_cast(const From &from) FL_NO_EXCEPT
Definition bit_cast.h:48

References fl::bit_cast(), fl::span< T, Extent >::data(), fl::end(), fl::ieee754_parse_decimal(), fl::parseInt(), fl::vector< T >::push_back(), and fl::span< T, Extent >::size().

Referenced by on_token().

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