Add newlines in MiniYaml.cs for readability

This commit is contained in:
Taryn Hill
2015-11-11 12:47:30 -06:00
parent 9b568f53a1
commit 44e03c094b

View File

@@ -36,6 +36,7 @@ namespace OpenRA
{ {
foreach (var line in kv.Value.ToLines(kv.Key)) foreach (var line in kv.Value.ToLines(kv.Key))
yield return line; yield return line;
if (lowest) if (lowest)
yield return ""; yield return "";
} }
@@ -158,13 +159,16 @@ namespace OpenRA
var commentIndex = line.IndexOf('#'); var commentIndex = line.IndexOf('#');
if (commentIndex != -1) if (commentIndex != -1)
line = line.Substring(0, commentIndex).TrimEnd(' ', '\t'); line = line.Substring(0, commentIndex).TrimEnd(' ', '\t');
if (line.Length == 0) if (line.Length == 0)
continue; continue;
var charPosition = 0; var charPosition = 0;
var level = 0; var level = 0;
var spaces = 0; var spaces = 0;
var textStart = false; var textStart = false;
var currChar = line[charPosition]; var currChar = line[charPosition];
while (!(currChar == '\n' || currChar == '\r') && charPosition < line.Length && !textStart) while (!(currChar == '\n' || currChar == '\r') && charPosition < line.Length && !textStart)
{ {
currChar = line[charPosition]; currChar = line[charPosition];
@@ -193,10 +197,12 @@ namespace OpenRA
var realText = line.Substring(charPosition); var realText = line.Substring(charPosition);
if (realText.Length == 0) if (realText.Length == 0)
continue; continue;
var location = new MiniYamlNode.SourceLocation { Filename = filename, Line = lineNo }; var location = new MiniYamlNode.SourceLocation { Filename = filename, Line = lineNo };
if (levels.Count <= level) if (levels.Count <= level)
throw new YamlException("Bad indent in miniyaml at {0}".F(location)); throw new YamlException("Bad indent in miniyaml at {0}".F(location));
while (levels.Count > level + 1) while (levels.Count > level + 1)
levels.RemoveAt(levels.Count - 1); levels.RemoveAt(levels.Count - 1);
@@ -215,9 +221,11 @@ namespace OpenRA
var colon = realText.IndexOf(':'); var colon = realText.IndexOf(':');
if (colon == -1) if (colon == -1)
return null; return null;
var ret = realText.Substring(colon + 1).Trim(); var ret = realText.Substring(colon + 1).Trim();
if (ret.Length == 0) if (ret.Length == 0)
ret = null; ret = null;
realText = realText.Substring(0, colon).Trim(); realText = realText.Substring(0, colon).Trim();
return ret; return ret;
} }
@@ -268,6 +276,7 @@ namespace OpenRA
{ {
if (a.Count == 0) if (a.Count == 0)
return b; return b;
if (b.Count == 0) if (b.Count == 0)
return a; return a;
@@ -332,6 +341,7 @@ namespace OpenRA
{ {
if (a == null) if (a == null)
return b; return b;
if (b == null) if (b == null)
return a; return a;
@@ -341,6 +351,7 @@ namespace OpenRA
public IEnumerable<string> ToLines(string name) public IEnumerable<string> ToLines(string name)
{ {
yield return name + ": " + Value; yield return name + ": " + Value;
if (Nodes != null) if (Nodes != null)
foreach (var line in Nodes.ToLines(false)) foreach (var line in Nodes.ToLines(false))
yield return "\t" + line; yield return "\t" + line;