component provides util.ConfigSectionFile requires io.TextFile, data.StringUtil stringUtil, data.query.Search search {
ConfigSection sections[]
ConfigSectionFile:ConfigSectionFile(char configFile[])
{
TextFile file = new TextFile(configFile, File.READ)
if (file == null) throw new Exception("file '$configFile' not found")
ConfigSection csection
char line[]
while ((line = file.readLine()) != null)
{
line = line.trim()
if (line.startsWith("["))
{
if (!line.endsWith("]"))
{
throw new Exception("file format error: expected closing bracket on section header")
}
csection = new ConfigSection(line.subString(1, line.arrayLength-2))
sections = new ConfigSection[](sections, csection)
}
else if (line.arrayLength != 0)
{
if (line.find("=") != StringUtil.NOT_FOUND)
{
String parts[] = line.lsplit("=")
csection.values = new KeyValue[](csection.values, new KeyValue(parts[0].string, parts[1].string))
}
else
{
csection.values = new KeyValue[](csection.values, new KeyValue(line))
}
}
}
file.close()
}
ConfigSection ConfigSectionFile:getSection(char name[])
{
return sections.findFirst(ConfigSection.[name], new ConfigSection(name))
}
}To propose a new revision to this entity, use dana source put -uc your/new/version.dn -n util.ConfigSectionFile -m "reason for update" -u yourUsername
Version 1 (this version) by barry
Notes for this version: Adds support for optional headers, updates config file format to an extensible one, adds sectional config file parser