StyleCop clean MiniYaml

This commit is contained in:
Matthias Mailänder
2013-08-07 15:51:19 +02:00
parent 05f165357d
commit 57f7f71c8d

View File

@@ -17,6 +17,30 @@ namespace OpenRA.FileFormats
{
using MiniYamlNodes = List<MiniYamlNode>;
public static class MiniYamlExts
{
public static void WriteToFile(this MiniYamlNodes y, string filename)
{
File.WriteAllLines(filename, y.ToLines(true).Select(x => x.TrimEnd()).ToArray());
}
public static string WriteToString(this MiniYamlNodes y)
{
return y.ToLines(true).Select(x => x.TrimEnd()).JoinWith("\n");
}
public static IEnumerable<string> ToLines(this MiniYamlNodes y, bool lowest)
{
foreach (var kv in y)
{
foreach (var line in kv.Value.ToLines(kv.Key))
yield return line;
if (lowest)
yield return "";
}
}
}
public class MiniYamlNode
{
public struct SourceLocation
@@ -42,18 +66,13 @@ namespace OpenRA.FileFormats
}
public MiniYamlNode(string k, string v)
: this( k, v, null )
{
}
: this(k, v, null) { }
public MiniYamlNode(string k, string v, List<MiniYamlNode> n)
: this( k, new MiniYaml( v, n ) )
{
}
: this(k, new MiniYaml(v, n)) { }
public MiniYamlNode(string k, string v, List<MiniYamlNode> n, SourceLocation loc)
: this( k, new MiniYaml( v, n ), loc )
{
}
: this(k, new MiniYaml(v, n), loc) { }
public override string ToString()
{
@@ -77,6 +96,7 @@ namespace OpenRA.FileFormats
throw new InvalidDataException("Duplicate key `{0}' in MiniYaml".F(y.Key));
ret.Add(y.Key, y.Value);
}
return ret;
}
}
@@ -133,6 +153,7 @@ namespace OpenRA.FileFormats
levels.Add(d);
}
return levels[0];
}
@@ -205,9 +226,9 @@ namespace OpenRA.FileFormats
var ret = new List<MiniYamlNode>();
var aDict = a.ToDictionaryWithConflictLog(x => x.Key, "MiniYaml.Merge", null, x => "{0} (at {1})".F(x.Key, x.Location));
var bDict = b.ToDictionaryWithConflictLog(x => x.Key, "MiniYaml.Merge", null, x => "{0} (at {1})".F(x.Key, x.Location));
var keys = aDict.Keys.Union( bDict.Keys ).ToList();
var dictA = a.ToDictionaryWithConflictLog(x => x.Key, "MiniYaml.Merge", null, x => "{0} (at {1})".F(x.Key, x.Location));
var dictB = b.ToDictionaryWithConflictLog(x => x.Key, "MiniYaml.Merge", null, x => "{0} (at {1})".F(x.Key, x.Location));
var keys = dictA.Keys.Union(dictB.Keys).ToList();
var noInherit = keys.Where(x => x.Length > 0 && x[0] == '-')
.ToDictionary(x => x.Substring(1), x => false);
@@ -215,8 +236,8 @@ namespace OpenRA.FileFormats
foreach (var key in keys)
{
MiniYamlNode aa, bb;
aDict.TryGetValue( key, out aa );
bDict.TryGetValue( key, out bb );
dictA.TryGetValue(key, out aa);
dictB.TryGetValue(key, out bb);
if (noInherit.ContainsKey(key))
{
@@ -271,30 +292,6 @@ namespace OpenRA.FileFormats
}
}
public static class MiniYamlExts
{
public static void WriteToFile(this MiniYamlNodes y, string filename)
{
File.WriteAllLines(filename, y.ToLines(true).Select(x => x.TrimEnd()).ToArray());
}
public static string WriteToString(this MiniYamlNodes y)
{
return y.ToLines(true).Select(x => x.TrimEnd()).JoinWith("\n");
}
public static IEnumerable<string> ToLines(this MiniYamlNodes y, bool lowest)
{
foreach (var kv in y)
{
foreach (var line in kv.Value.ToLines(kv.Key))
yield return line;
if (lowest)
yield return "";
}
}
}
public class YamlException : Exception
{
public YamlException(string s) : base(s) { }