more yaml read/write flexibility: strings
This commit is contained in:
@@ -21,10 +21,8 @@ namespace OpenRa.FileFormats
|
||||
Nodes = nodes;
|
||||
}
|
||||
|
||||
public static Dictionary<string, MiniYaml> FromFile( string path )
|
||||
static Dictionary<string, MiniYaml> FromLines(string[] lines)
|
||||
{
|
||||
var lines = File.ReadAllLines( path );
|
||||
|
||||
var levels = new List<Dictionary<string, MiniYaml>>();
|
||||
levels.Add(new Dictionary<string, MiniYaml>());
|
||||
|
||||
@@ -57,6 +55,16 @@ namespace OpenRa.FileFormats
|
||||
return levels[0];
|
||||
}
|
||||
|
||||
public static Dictionary<string, MiniYaml> FromFile( string path )
|
||||
{
|
||||
return FromLines(File.ReadAllLines( path ));
|
||||
}
|
||||
|
||||
public static Dictionary<string, MiniYaml> FromString(string text)
|
||||
{
|
||||
return FromLines(text.Split('\n'));
|
||||
}
|
||||
|
||||
public static Dictionary<string, MiniYaml> Merge( Dictionary<string, MiniYaml> a, Dictionary<string, MiniYaml> b )
|
||||
{
|
||||
if( a.Count == 0 )
|
||||
@@ -116,6 +124,11 @@ namespace OpenRa.FileFormats
|
||||
File.WriteAllLines(filename, y.ToLines(true).Select(x => x.TrimEnd()).ToArray());
|
||||
}
|
||||
|
||||
public static string WriteToString(this MiniYamlNodes y)
|
||||
{
|
||||
return string.Join("\n", y.ToLines(true).Select(x => x.TrimEnd()).ToArray());
|
||||
}
|
||||
|
||||
public static IEnumerable<string> ToLines(this MiniYamlNodes y, bool lowest)
|
||||
{
|
||||
foreach (var kv in y)
|
||||
|
||||
Reference in New Issue
Block a user