MCPcopy Create free account
hub / github.com/FastLED/FastLED / scan_array_lookahead

Method scan_array_lookahead

src/fl/stl/json.cpp.hpp:138–311  ·  view source on GitHub ↗

Array lookahead scanner - scans array to determine if it can be optimized Returns specialized token (ARRAY_UINT8, etc.) or LBRACKET for slow path Assumes mPos is positioned after '[' character

Source from the content-addressed store, hash-verified

136 // Returns specialized token (ARRAY_UINT8, etc.) or LBRACKET for slow path
137 // Assumes mPos is positioned after '[' character
138 JsonToken scan_array_lookahead(fl::span<const char>& out_span) {
139 if (!mEnableLookahead) {
140 return JsonToken::LBRACKET; // Lookahead disabled
141 }
142
143 size_t start_pos = mPos; // Position after '['
144
145 // Track element types and ranges
146 bool has_int = false;
147 bool has_float = false;
148 bool has_float_beyond_precision = false; // Track floats > 2^24
149 bool has_string = false;
150 bool has_bool = false;
151 bool has_null = false;
152 i64 int_min = fl::numeric_limits<i64>::max();
153 i64 int_max = fl::numeric_limits<i64>::min();
154
155 skip_whitespace();
156
157 // Empty array - use slow path
158 if (mPos < mLen && mInput[mPos] == ']') {
159 out_span = fl::span<const char>();
160 return JsonToken::LBRACKET;
161 }
162
163 // Scan elements
164 while (mPos < mLen) {
165 skip_whitespace();
166
167 // Check for array end
168 if (mInput[mPos] == ']') {
169 break;
170 }
171
172 char c = mInput[mPos];
173
174 // Abort on nested structures
175 if (c == '[' || c == '{') {
176 return JsonToken::LBRACKET;
177 }
178
179 // STRING
180 if (c == '"') {
181 has_string = true;
182 mPos++;
183 while (mPos < mLen) {
184 if (mInput[mPos] == '\\') {
185 mPos += 2; // Skip escape sequence
186 } else if (mInput[mPos] == '"') {
187 mPos++;
188 break;
189 } else {
190 mPos++;
191 }
192 }
193 }
194 // NUMBER
195 else if (c == '-' || (c >= '0' && c <= '9')) {

Callers

nothing calls this directly

Calls 4

maxFunction · 0.85
ieee754_parse_decimalFunction · 0.85
parseIntFunction · 0.70

Tested by

no test coverage detected