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

Function parse_lnk

src/fl/stl/url.h:274–310  ·  view source on GitHub ↗

Parse the contents of a `.lnk` file into a `fl::url`. Format: one URL per line. Leading/trailing whitespace on each line is ignored. Blank lines and lines whose first non-whitespace character is `#` are treated as comments and skipped. The first non-comment, non-blank line is returned as a `fl::url`. Future-compat: additional lines (metadata like `sha256=...`, `fallback=...`) are ignored by this

Source from the content-addressed store, hash-verified

272/// See also `parse_lnk_with_metadata()` which returns the URL alongside the
273/// (currently unenforced) metadata fields for forward-compat callers.
274inline url parse_lnk(fl::string_view content) FL_NOEXCEPT {
275 fl::size pos = 0;
276 while (pos < content.size()) {
277 fl::size eol = content.find('\n', pos);
278 fl::size lineEnd = (eol == fl::string_view::npos) ? content.size() : eol;
279 fl::string_view line = content.substr(pos, lineEnd - pos);
280 pos = (eol == fl::string_view::npos) ? content.size() : eol + 1;
281
282 // Strip a trailing '\r' from CRLF line endings.
283 if (!line.empty() && line[line.size() - 1] == '\r') {
284 line = line.substr(0, line.size() - 1);
285 }
286
287 // Trim leading whitespace.
288 fl::size s = 0;
289 while (s < line.size() &&
290 (line[s] == ' ' || line[s] == '\t')) {
291 ++s;
292 }
293 // Trim trailing whitespace.
294 fl::size e = line.size();
295 while (e > s &&
296 (line[e - 1] == ' ' || line[e - 1] == '\t')) {
297 --e;
298 }
299 line = line.substr(s, e - s);
300
301 if (line.empty()) {
302 continue;
303 }
304 if (line[0] == '#') {
305 continue;
306 }
307 return url(line);
308 }
309 return url();
310}
311
312/// Parse a `.lnk` file into URL + metadata (forward-compat).
313///

Callers 2

resolve_hostFunction · 0.85
FL_TEST_FILEFunction · 0.85

Calls 5

urlClass · 0.85
sizeMethod · 0.45
findMethod · 0.45
substrMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected