From 961bf05e7e71a4dbfd1ed1641afbed4e90c10464 Mon Sep 17 00:00:00 2001 From: MichaƂ Klichowicz Date: Fri, 18 Sep 2026 10:16:07 +0200 Subject: * ignoring multiple/leading empty lines * error readability improvements --- src/PBNFile.cs | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'src/PBNFile.cs') diff --git a/src/PBNFile.cs b/src/PBNFile.cs index b26f84c..f2a1465 100644 --- a/src/PBNFile.cs +++ b/src/PBNFile.cs @@ -9,6 +9,7 @@ namespace BCDD class PBNFile { public List Boards; + public Dictionary ParseErrors; private String filename; private String tmpFileName; @@ -18,28 +19,40 @@ namespace BCDD public PBNFile(String filename) { this.filename = filename; + this.ParseErrors = new Dictionary(); this.Boards = new List(); - String[] contents = File.ReadAllLines(this.filename).Select(l => l.Trim()).ToArray(); + List contents = File.ReadAllLines(this.filename).Select(l => l.Trim()).ToList(); + if (!contents.Last().Equals("")) + { + contents.Add(""); + } List lines = new List(); - foreach (String line in contents) + int lineNo = 0; + for (int l = 0; l < contents.Count; l++) { - if (line.Length == 0) + String line = contents[l]; + if (line.Length != 0) { - if (lines.Count > 0) - { - this.Boards.Add(new PBNBoard(lines)); - lines = new List(); - } + lines.Add(line); + continue; } else { - lines.Add(line); + if (lines.Count > 0) // ignore leading or multiple empty lines + { + try + { + this.Boards.Add(new PBNBoard(lines)); + } + catch (Exception ex) + { + this.ParseErrors[lineNo+1] = ex.Message; + } + lines = new List(); + lineNo = l; + } } } - if (lines.Count > 0) - { - this.Boards.Add(new PBNBoard(lines)); - } if (!this.Boards[0].HasField("Event")) { this.Boards[0].WriteEvent(""); -- cgit v1.3.1