summaryrefslogtreecommitdiff
path: root/src/PBNFile.cs
diff options
context:
space:
mode:
authorMichał Klichowicz <emkael@tlen.pl>2026-09-18 10:16:07 +0200
committerMichał Klichowicz <emkael@tlen.pl>2026-09-18 10:16:07 +0200
commit961bf05e7e71a4dbfd1ed1641afbed4e90c10464 (patch)
tree91f53c14d83ca31b84b882be8db577199920d1e6 /src/PBNFile.cs
parent71f005f4e939d71d64f00c66748963f8895434d0 (diff)
* ignoring multiple/leading empty lines
* error readability improvements
Diffstat (limited to 'src/PBNFile.cs')
-rw-r--r--src/PBNFile.cs39
1 files changed, 26 insertions, 13 deletions
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<PBNBoard> Boards;
+ public Dictionary<int, String> ParseErrors;
private String filename;
private String tmpFileName;
@@ -18,28 +19,40 @@ namespace BCDD
public PBNFile(String filename)
{
this.filename = filename;
+ this.ParseErrors = new Dictionary<int, string>();
this.Boards = new List<PBNBoard>();
- String[] contents = File.ReadAllLines(this.filename).Select(l => l.Trim()).ToArray();
+ List<String> contents = File.ReadAllLines(this.filename).Select(l => l.Trim()).ToList();
+ if (!contents.Last().Equals(""))
+ {
+ contents.Add("");
+ }
List<String> lines = new List<String>();
- 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<String>();
- }
+ 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<String>();
+ lineNo = l;
+ }
}
}
- if (lines.Count > 0)
- {
- this.Boards.Add(new PBNBoard(lines));
- }
if (!this.Boards[0].HasField("Event"))
{
this.Boards[0].WriteEvent("");