Add next_entry
This commit is contained in:
parent
cabc7c1e19
commit
b42b1b1dd2
@ -17,7 +17,8 @@ export type comment = str;
|
|||||||
// Specification: §3.2
|
// Specification: §3.2
|
||||||
export type group_header = str;
|
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
|
// Specification: §3.3, §5
|
||||||
export type entry = struct {
|
export type entry = struct {
|
||||||
group: str,
|
group: str,
|
||||||
|
@ -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
|
// Returns the next line from a desktop entry file. The return value is
|
||||||
// borrowed from the [[scanner]] use [[line_dup]] to retain a copy.
|
// 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) = {
|
export fn next(this: *scanner) (line | io::EOF | error) = {
|
||||||
let text = match (bufio::scan_line(&this.scanner)) {
|
let text = match (bufio::scan_line(&this.scanner)) {
|
||||||
case let text: const str =>
|
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]].
|
// Frees resources associated with a [[scanner]].
|
||||||
export fn finish(this: *scanner) void = {
|
export fn finish(this: *scanner) void = {
|
||||||
|
Loading…
Reference in New Issue
Block a user