2using System.Collections.Generic;
4using System.Text.RegularExpressions;
13 public static GroupCollection? MatchGroup(
16 RegexOptions options = RegexOptions.CultureInvariant | RegexOptions.Multiline)
18 var match = Regex.Match(text, pattern, options);
22 public static GroupCollection? Fetch(
this GroupCollection groups,
string capturename, out
string result)
24 result = groups[capturename].Value;
37 CommandType.Set =>
"",
38 CommandType.Add =>
"+",
39 CommandType.Remove =>
"-",
40 CommandType.Clear =>
"!",
41 CommandType.Comment =>
";",
54 public readonly Dictionary<string, ConfigSection>
Sections =
new();
68 var result =
this[key];
71 var lastOrder = Sections.Count > 0 ?
Sections.Values.Max(s => s.Order) + 1 : 0;
84 if (
string.IsNullOrWhiteSpace(input))
return null;
88 foreach(var lineIn
in input!.Split(
new [] {
"\r",
"\n" }, StringSplitOptions.None))
90 if (
string.IsNullOrWhiteSpace(lineIn))
continue;
91 var line = lineIn.Trim();
93 if (line.StartsWith(
"[") && line.EndsWith(
"]"))
95 var sectionName = line.TrimStart(
'[').TrimEnd(
']');
96 if (ini.Sections.ContainsKey(sectionName))
98 currentSection = ini.Sections[sectionName];
102 currentSection =
new() { Order = order, Name = sectionName };
103 ini.Sections.Add(sectionName, currentSection);
108 currentSection?.SetLine(line, order);
113 return order > 0 ? ini :
null;
122 foreach(var fromSection
in from.Sections.Values)
124 var name = fromSection.Name ??
"";
131 Sections.Add(name, fromSection.Copy());
139 public string Serialize() =>
string.Join(Environment.NewLine,
140 Sections.Values.OrderBy(s => s.Order).Select(s => s.Serialize())
Utilities for parsing Unreal configuration files.
static string AsCharacter(this CommandType commandType)
Convert a command type into its representing character.
The root class representing Unreal INI configuration.
readonly Dictionary< string, ConfigSection > Sections
Sections separated by [SectionName] syntax.
string Serialize()
Convert this ConfigIni back to something Unreal can read.
void Merge(ConfigIni from)
Compose another ConfigIni instance into this one, overriding existing values and adding new ones.
ConfigSection FindOrAdd(string key)
Get an existing section or add it if it doesn't exist yet.
static ? ConfigIni Parse(string? input)
Parse an Unreal configuration text into a ConfigIni.
Represents a section block in an Unreal INI configuration under a [SectionName] header.
CommandType
Unreal INI config items are read top to bottom, reading like individual commands, especially when man...