Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 21 additions & 26 deletions source/dini/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct IniSection
protected IniSection* _parent;

/// Childs
protected IniSection[] _sections;
protected IniSection[string] _sections;

/// Keys
protected string[string] _keys;
Expand Down Expand Up @@ -158,7 +158,13 @@ struct IniSection
*/
public void addSection(ref IniSection section)
{
_sections ~= section;
if (hasSection(section._name)) {
foreach (key; section._keys.keys) {
_sections[section._name]._keys[key] = section._keys[key];
}
} else {
_sections[section._name] = section;
}
}

/**
Expand All @@ -172,12 +178,9 @@ struct IniSection
*/
public bool hasSection(string name)
{
foreach(ref section; _sections)
{
if(section.name() == name)
return true;
if (name in _sections) {
return true;
}

return false;
}

Expand All @@ -192,13 +195,10 @@ struct IniSection
*/
public ref IniSection getSection(string name)
{
foreach(ref section; _sections)
{
if(section.name() == name)
return section;
if (!(hasSection(name))) {
throw new IniException("Section '"~name~"' does not exists");
}

throw new IniException("Section '"~name~"' does not exists");
return _sections[name];
}


Expand All @@ -213,15 +213,10 @@ struct IniSection
*/
public void removeSection(string name)
{
IniSection[] childs;

foreach(section; _sections)
{
if(section.name != name)
childs ~= section;
if (!(hasSection(name))) {
return;
}

_sections = childs;
_sections.remove(name);
}

/**
Expand All @@ -247,12 +242,12 @@ struct IniSection
}

/**
* Array of sections
* Associative array of sections
*
* Returns:
* Array of sections
*/
public IniSection[] sections() @property
public IniSection[string] sections() @property
{
return _sections;
}
Expand Down Expand Up @@ -405,7 +400,6 @@ struct IniSection
}

newValue = sect.getSectionEx(parts[0..$-1].join(".").idup).getKey(parts[$-1].idup);

value.replaceInPlace(start, i+1, newValue);
start = -1;
buf = [];
Expand Down Expand Up @@ -454,10 +448,11 @@ struct IniSection
*/
public void inherit(IniSection sect)
{
this._keys = sect.keys().dup;
foreach (key; sect._keys.keys) {
this._keys[key] = sect._keys[key].dup;
}
}


public void save(string filename)
{
import std.file;
Expand Down