FastLED 3.9.15
Loading...
Searching...
No Matches

◆ parse_lnk()

url fl::parse_lnk ( fl::string_view content)
inline

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 v1 parser so older binaries keep working when future .lnk files grow richer.

See also parse_lnk_with_metadata() which returns the URL alongside the (currently unenforced) metadata fields for forward-compat callers.

Definition at line 274 of file url.h.

274 {
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}
uint8_t pos
Definition Blur.ino:11
constexpr bool empty() const FL_NOEXCEPT
static constexpr fl::size npos
Definition string_view.h:35
constexpr fl::size size() const FL_NOEXCEPT
Definition string_view.h:99
fl::size find(char ch, fl::size pos=0) const FL_NOEXCEPT
string_view substr(fl::size pos=0, fl::size count=npos) const FL_NOEXCEPT
Definition url.h:15

References fl::string_view::empty(), FL_NOEXCEPT, fl::string_view::npos, pos, fl::string_view::size(), and fl::string_view::substr().

+ Here is the call graph for this function: