From 9b568f53a170b3cefc275fae6e2856ec89a24b5f Mon Sep 17 00:00:00 2001 From: Taryn Hill Date: Wed, 11 Nov 2015 12:44:04 -0600 Subject: [PATCH 1/3] Rename some variables in MiniYaml.cs for readability --- OpenRA.Game/MiniYaml.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index 3075bf2a08..8b8b15a665 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -160,15 +160,15 @@ namespace OpenRA line = line.Substring(0, commentIndex).TrimEnd(' ', '\t'); if (line.Length == 0) continue; - var cp = 0; + var charPosition = 0; var level = 0; var spaces = 0; var textStart = false; - var c = line[cp]; - while (!(c == '\n' || c == '\r') && cp < line.Length && !textStart) + var currChar = line[charPosition]; + while (!(currChar == '\n' || currChar == '\r') && charPosition < line.Length && !textStart) { - c = line[cp]; - switch (c) + currChar = line[charPosition]; + switch (currChar) { case ' ': spaces++; @@ -178,11 +178,11 @@ namespace OpenRA level++; } - cp++; + charPosition++; break; case '\t': level++; - cp++; + charPosition++; break; default: textStart = true; @@ -190,8 +190,8 @@ namespace OpenRA } } - var t = line.Substring(cp); - if (t.Length == 0) + var realText = line.Substring(charPosition); + if (realText.Length == 0) continue; var location = new MiniYamlNode.SourceLocation { Filename = filename, Line = lineNo }; @@ -201,8 +201,8 @@ namespace OpenRA levels.RemoveAt(levels.Count - 1); var d = new List(); - var rhs = SplitAtColon(ref t); - levels[level].Add(new MiniYamlNode(t, rhs, d, location)); + var rhs = SplitAtColon(ref realText); + levels[level].Add(new MiniYamlNode(realText, rhs, d, location)); levels.Add(d); } @@ -210,15 +210,15 @@ namespace OpenRA return levels[0]; } - static string SplitAtColon(ref string t) + static string SplitAtColon(ref string realText) { - var colon = t.IndexOf(':'); + var colon = realText.IndexOf(':'); if (colon == -1) return null; - var ret = t.Substring(colon + 1).Trim(); + var ret = realText.Substring(colon + 1).Trim(); if (ret.Length == 0) ret = null; - t = t.Substring(0, colon).Trim(); + realText = realText.Substring(0, colon).Trim(); return ret; } From 44e03c094b7a9d12065dd537dc2a60b8a6d513ee Mon Sep 17 00:00:00 2001 From: Taryn Hill Date: Wed, 11 Nov 2015 12:47:30 -0600 Subject: [PATCH 2/3] Add newlines in MiniYaml.cs for readability --- OpenRA.Game/MiniYaml.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index 8b8b15a665..4e346fa60b 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -36,6 +36,7 @@ namespace OpenRA { foreach (var line in kv.Value.ToLines(kv.Key)) yield return line; + if (lowest) yield return ""; } @@ -158,13 +159,16 @@ namespace OpenRA var commentIndex = line.IndexOf('#'); if (commentIndex != -1) line = line.Substring(0, commentIndex).TrimEnd(' ', '\t'); + if (line.Length == 0) continue; + var charPosition = 0; var level = 0; var spaces = 0; var textStart = false; var currChar = line[charPosition]; + while (!(currChar == '\n' || currChar == '\r') && charPosition < line.Length && !textStart) { currChar = line[charPosition]; @@ -193,10 +197,12 @@ namespace OpenRA var realText = line.Substring(charPosition); if (realText.Length == 0) continue; + var location = new MiniYamlNode.SourceLocation { Filename = filename, Line = lineNo }; if (levels.Count <= level) throw new YamlException("Bad indent in miniyaml at {0}".F(location)); + while (levels.Count > level + 1) levels.RemoveAt(levels.Count - 1); @@ -215,9 +221,11 @@ namespace OpenRA var colon = realText.IndexOf(':'); if (colon == -1) return null; + var ret = realText.Substring(colon + 1).Trim(); if (ret.Length == 0) ret = null; + realText = realText.Substring(0, colon).Trim(); return ret; } @@ -268,6 +276,7 @@ namespace OpenRA { if (a.Count == 0) return b; + if (b.Count == 0) return a; @@ -332,6 +341,7 @@ namespace OpenRA { if (a == null) return b; + if (b == null) return a; @@ -341,6 +351,7 @@ namespace OpenRA public IEnumerable ToLines(string name) { yield return name + ": " + Value; + if (Nodes != null) foreach (var line in Nodes.ToLines(false)) yield return "\t" + line; From a8600ffbe72f6179a21053d0b730dc3efd171cca Mon Sep 17 00:00:00 2001 From: Taryn Hill Date: Wed, 11 Nov 2015 13:03:22 -0600 Subject: [PATCH 3/3] Replace instance of 4 spaces with a single tab in MiniYaml.cs --- OpenRA.Game/MiniYaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index 4e346fa60b..32b2a77203 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -174,7 +174,7 @@ namespace OpenRA currChar = line[charPosition]; switch (currChar) { - case ' ': + case ' ': spaces++; if (spaces >= SpacesPerLevel) {