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

Function parse_lnk_with_metadata

src/fl/stl/url.h:325–377  ·  view source on GitHub ↗

Parse a `.lnk` file into URL + metadata (forward-compat). Accepts the same format as `parse_lnk()` and additionally scans non-comment `key=value` lines that follow the primary URL. Recognized keys: - `sha256= ` — stored in `LnkMetadata::sha256` - `fallback= ` — stored in `LnkMetadata::fallback` Unknown keys are silently ignored (forward-compat). v1: the returned metadata is parsed but

Source from the content-addressed store, hash-verified

323/// are reserved for future integrity/retry features so existing `.lnk`
324/// files remain valid when richer behavior lands.
325inline LnkMetadata parse_lnk_with_metadata(fl::string_view content) FL_NOEXCEPT {
326 LnkMetadata out;
327 bool gotPrimary = false;
328 fl::size pos = 0;
329 while (pos < content.size()) {
330 fl::size eol = content.find('\n', pos);
331 fl::size lineEnd = (eol == fl::string_view::npos) ? content.size() : eol;
332 fl::string_view line = content.substr(pos, lineEnd - pos);
333 pos = (eol == fl::string_view::npos) ? content.size() : eol + 1;
334
335 if (!line.empty() && line[line.size() - 1] == '\r') {
336 line = line.substr(0, line.size() - 1);
337 }
338
339 fl::size s = 0;
340 while (s < line.size() &&
341 (line[s] == ' ' || line[s] == '\t')) {
342 ++s;
343 }
344 fl::size e = line.size();
345 while (e > s &&
346 (line[e - 1] == ' ' || line[e - 1] == '\t')) {
347 --e;
348 }
349 line = line.substr(s, e - s);
350
351 if (line.empty() || line[0] == '#') {
352 continue;
353 }
354
355 if (!gotPrimary) {
356 out.primary = url(line);
357 gotPrimary = true;
358 continue;
359 }
360
361 // Subsequent lines: look for "key=value" metadata.
362 fl::size eq = line.find('=');
363 if (eq == fl::string_view::npos) {
364 // Unknown non-kv line, ignore (forward-compat).
365 continue;
366 }
367 fl::string_view key = line.substr(0, eq);
368 fl::string_view value = line.substr(eq + 1);
369 if (key == "sha256") {
370 out.sha256 = fl::string(value.data(), value.size());
371 } else if (key == "fallback") {
372 out.fallback = url(value);
373 }
374 // else: unknown key, ignore.
375 }
376 return out;
377}
378
379} // namespace fl

Callers 1

FL_TEST_FILEFunction · 0.85

Calls 7

urlClass · 0.85
stringClass · 0.70
sizeMethod · 0.45
findMethod · 0.45
substrMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected