loadPrefsFile method Null safety
- File file
Load a prefs file and parse the content into a set of PrefsOption
.
For lines which can't be properly parsed a message is printed and the line
is otherwise ignored.
Comments, lines starting with //
are silently ignored.
Implementation
static Set<PrefsOption> loadPrefsFile(io.File file) {
final prefs = <PrefsOption>{};
final lines = LineSplitter.split(file.readAsStringSync())
.where((line) => !_ignoreLine(line));
var canNotParseCaption = true;
for (final line in lines) {
final option = PrefsOption.parse(line);
if (option is InvalidOption) {
if (canNotParseCaption) {
print('Can\'t parse lines from file "${file.path}":');
canNotParseCaption = false;
}
print(' $line');
continue;
}
prefs.add(option);
}
return prefs;
}