From b42b1b1dd21307922f5685dff280b4f483c4d2ba Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 19 Oct 2024 16:23:13 -0400 Subject: [PATCH] Add next_entry --- format/desktop_entry/desktop_entry.ha | 3 ++- format/desktop_entry/scan.ha | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/format/desktop_entry/desktop_entry.ha b/format/desktop_entry/desktop_entry.ha index 6e34edc..2eb27ee 100644 --- a/format/desktop_entry/desktop_entry.ha +++ b/format/desktop_entry/desktop_entry.ha @@ -17,7 +17,8 @@ export type comment = str; // Specification: §3.2 export type group_header = str; -// An entry in a desktop file. +// An entry in a desktop file. Entries without an explicitly stated locale are +// assigned [[locale::c]]. // Specification: §3.3, §5 export type entry = struct { group: str, diff --git a/format/desktop_entry/scan.ha b/format/desktop_entry/scan.ha index 1e9ea92..a103fa5 100644 --- a/format/desktop_entry/scan.ha +++ b/format/desktop_entry/scan.ha @@ -18,8 +18,10 @@ export fn scan(input: io::handle) scanner = scanner { ... }; -// Returns the next entry from a desktop entry file. The return value is -// borrowed from the [[scanner]] use [[line_dup]] to retain a copy. +// Returns the next line from a desktop entry file. The return value is +// borrowed from the [[scanner]]. Use [[line_dup]] to retain a copy. If all you +// want is the file's data, use next_entry. +// FIXME: there is no line_dup export fn next(this: *scanner) (line | io::EOF | error) = { let text = match (bufio::scan_line(&this.scanner)) { case let text: const str => @@ -53,7 +55,16 @@ export fn next(this: *scanner) (line | io::EOF | error) = { }; }; -// TODO: have next_entry that auto-skips over blank lines and comments +// Returns the next entry from the desktop file, skipping over blank lines, +// comments, group headers, etc. The return value is borrowed from the +// [[scanner]]. Use [[entry_dup]] to retain a copy. +export fn next_entry(this: *scanner) (entry | io::EOF | error) = { + for (true) match(next(this)?) { + case let entr: entry => return entr; + case io::EOF => return io::EOF; + case => void; + }; +}; // Frees resources associated with a [[scanner]]. export fn finish(this: *scanner) void = {