StyleCop clean MiniYaml
This commit is contained in:
@@ -17,6 +17,30 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
using MiniYamlNodes = List<MiniYamlNode>;
|
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 class MiniYamlNode
|
||||||
{
|
{
|
||||||
public struct SourceLocation
|
public struct SourceLocation
|
||||||
@@ -42,18 +66,13 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MiniYamlNode(string k, string v)
|
public MiniYamlNode(string k, string v)
|
||||||
: this( k, v, null )
|
: this(k, v, null) { }
|
||||||
{
|
|
||||||
}
|
|
||||||
public MiniYamlNode(string k, string v, List<MiniYamlNode> n)
|
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)
|
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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
@@ -77,6 +96,7 @@ namespace OpenRA.FileFormats
|
|||||||
throw new InvalidDataException("Duplicate key `{0}' in MiniYaml".F(y.Key));
|
throw new InvalidDataException("Duplicate key `{0}' in MiniYaml".F(y.Key));
|
||||||
ret.Add(y.Key, y.Value);
|
ret.Add(y.Key, y.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,6 +153,7 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
levels.Add(d);
|
levels.Add(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
return levels[0];
|
return levels[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,9 +226,9 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
var ret = new List<MiniYamlNode>();
|
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 dictA = 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 dictB = 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 keys = dictA.Keys.Union(dictB.Keys).ToList();
|
||||||
|
|
||||||
var noInherit = keys.Where(x => x.Length > 0 && x[0] == '-')
|
var noInherit = keys.Where(x => x.Length > 0 && x[0] == '-')
|
||||||
.ToDictionary(x => x.Substring(1), x => false);
|
.ToDictionary(x => x.Substring(1), x => false);
|
||||||
@@ -215,8 +236,8 @@ namespace OpenRA.FileFormats
|
|||||||
foreach (var key in keys)
|
foreach (var key in keys)
|
||||||
{
|
{
|
||||||
MiniYamlNode aa, bb;
|
MiniYamlNode aa, bb;
|
||||||
aDict.TryGetValue( key, out aa );
|
dictA.TryGetValue(key, out aa);
|
||||||
bDict.TryGetValue( key, out bb );
|
dictB.TryGetValue(key, out bb);
|
||||||
|
|
||||||
if (noInherit.ContainsKey(key))
|
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 class YamlException : Exception
|
||||||
{
|
{
|
||||||
public YamlException(string s) : base(s) { }
|
public YamlException(string s) : base(s) { }
|
||||||
|
|||||||
Reference in New Issue
Block a user