Skip to content

Commit

Permalink
parsing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherPotato committed Aug 17, 2024
1 parent 0eae58f commit fccb140
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion extensions/Sisk.IniConfiguration/IniDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static IniDocument FromStream(TextReader reader)

internal IniDocument(IniSection[] sections)
{
Sections = sections;
Sections = IniSection.MergeIniSections(sections);
}

/// <summary>
Expand Down
28 changes: 28 additions & 0 deletions extensions/Sisk.IniConfiguration/IniSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@ public sealed class IniSection : IReadOnlyDictionary<string, string[]>
/// </summary>
public string Name { get; }

internal static IniSection[] MergeIniSections(IniSection[] sections)
{
var sectionNames = sections
.DistinctBy(s => s.Name, IniReader.IniNamingComparer)
.Select(s => s.Name)
.ToArray();

List<IniSection> result = new List<IniSection>(sectionNames.Length);
for (int i = 0; i < sectionNames.Length; i++)
{
string currentName = sectionNames[i];
List<(string, string)> allProperties = new();

for (int j = 0; j < sections.Length; j++)
{
IniSection s = sections[j];
if (IniReader.IniNamingComparer.Compare(s.Name, currentName) == 0)
{
allProperties.AddRange(s.items);
}
}

result.Add(new IniSection(currentName, allProperties.ToArray()));
}

return result.ToArray();
}

internal IniSection(string name, (string, string)[] items)
{
this.items = items;
Expand Down

0 comments on commit fccb140

Please sign in to comment.