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

◆ parse_lnk_with_metadata()

LnkMetadata fl::parse_lnk_with_metadata ( fl::string_view content)
inline

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:

This parser only extracts the fields. Enforcement lives in the WASM browser loader, which verifies sha256 and retries fallback (#4025); C++ resolution on other platforms still uses only the primary URL.

Definition at line 324 of file url.h.

324 {
325 LnkMetadata out;
326 bool gotPrimary = false;
327 fl::size pos = 0;
328 while (pos < content.size()) {
329 fl::size eol = content.find('\n', pos);
330 fl::size lineEnd = (eol == fl::string_view::npos) ? content.size() : eol;
331 fl::string_view line = content.substr(pos, lineEnd - pos);
332 pos = (eol == fl::string_view::npos) ? content.size() : eol + 1;
333
334 if (!line.empty() && line[line.size() - 1] == '\r') {
335 line = line.substr(0, line.size() - 1);
336 }
337
338 fl::size s = 0;
339 while (s < line.size() &&
340 (line[s] == ' ' || line[s] == '\t')) {
341 ++s;
342 }
343 fl::size e = line.size();
344 while (e > s &&
345 (line[e - 1] == ' ' || line[e - 1] == '\t')) {
346 --e;
347 }
348 line = line.substr(s, e - s);
349
350 if (line.empty() || line[0] == '#') {
351 continue;
352 }
353
354 if (!gotPrimary) {
355 out.primary = url(line);
356 gotPrimary = true;
357 continue;
358 }
359
360 // Subsequent lines: look for "key=value" metadata.
361 fl::size eq = line.find('=');
362 if (eq == fl::string_view::npos) {
363 // Unknown non-kv line, ignore (forward-compat).
364 continue;
365 }
366 fl::string_view key = line.substr(0, eq);
367 fl::string_view value = line.substr(eq + 1);
368 if (key == "sha256") {
369 out.sha256 = fl::string(value.data(), value.size());
370 } else if (key == "fallback") {
371 out.fallback = url(value);
372 }
373 // else: unknown key, ignore.
374 }
375 return out;
376}
uint8_t pos
Definition Blur.ino:11
string_view substr(fl::size pos=0, fl::size count=npos) const FL_NO_EXCEPT
constexpr fl::size size() const FL_NO_EXCEPT
Definition string_view.h:99
static constexpr fl::size npos
Definition string_view.h:35
fl::size find(char ch, fl::size pos=0) const FL_NO_EXCEPT
constexpr bool empty() const FL_NO_EXCEPT
Definition url.h:15
constexpr int type_rank< T >::value
fl::url primary
First non-comment URL in the file.
Definition url.h:253
fl::url fallback
Mirror URL used if primary fails.
Definition url.h:255
fl::string sha256
Hex-encoded sha256 of the expected asset.
Definition url.h:254
Metadata extracted from a .lnk asset link file.
Definition url.h:252

References fl::string_view::empty(), fl::LnkMetadata::fallback, fl::string_view::find(), FL_NO_EXCEPT, fl::string_view::npos, pos, fl::LnkMetadata::primary, fl::LnkMetadata::sha256, fl::string_view::size(), fl::string_view::substr(), and type_rank< T >::value.

+ Here is the call graph for this function: