diff --git a/ConfigParser.cs b/ConfigParser.cs index 7a49b3b699a9c74a7c4a54548f15885d215ea17f..65f453a37d85dc2189b125f808a25e445eb07b48 100644 --- a/ConfigParser.cs +++ b/ConfigParser.cs @@ -311,8 +311,35 @@ abstract class ConfigValue { return new ConfigParser(AsString(), Root.FileName, Line); } + public ConfigValue[] Lines() + { + int lineOfset = 0; + return AsString().Split("\n").Select(x => new ConfigValueSegment(this, x, lineOfset++)).Where(x => x.Value?.Trim() != "").ToArray(); + } + public ConfigValue[] Tokens() + { + return ( + from l in Lines() + from v in l.AsString().Split(new char[]{' ', '\t'}) + where v.Trim() != "" + select new ConfigValueSegment(l, v) + ).ToArray(); + } public static implicit operator string(ConfigValue v) => v.AsString(); } +class ConfigValueSegment: ConfigValue +{ + ConfigValue parent; + internal ConfigValueSegment(ConfigValue _parent, string _Value, int lineOfset=0): base(_parent.Root) + { + parent = _parent; + Line = parent.Line + lineOfset; + Value = _Value; + } + override public string FullName{ + get => parent.FullName; + } +} class ConfigOption: ConfigValue { public ConfigSection Section {get; init;}