From de13333bdef5458200e83f326a0a9e7f26de1681 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 23 May 2016 22:19:05 +0200 Subject: * PBN parsing regexes moved to static members --- PBNBoard.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/PBNBoard.cs b/PBNBoard.cs index e04fb37..72f87a4 100644 --- a/PBNBoard.cs +++ b/PBNBoard.cs @@ -39,15 +39,18 @@ namespace BCDD private bool? hasOptimumResultTable = null; private bool? hasAbility = null; + private static Regex linePattern = new Regex(@"\[(.*) ""(.*)""\]"); + private static Regex abilityPattern = new Regex(@"\b([NESW]):([0-9A-D]{5})\b"); + private static Regex optimumResultTablePattern = new Regex(@"^([NESW])\s+([CDHSN])T?\s+(\d+)$"); + public PBNBoard(List lines) { this.Fields = new List(); - Regex linePattern = new Regex(@"\[(.*) ""(.*)""\]"); foreach (String line in lines) { PBNField field = new PBNField(); field.RawField = line; - Match lineParse = linePattern.Match(line); + Match lineParse = PBNBoard.linePattern.Match(line); if (lineParse.Success) { field.Key = lineParse.Groups[1].Value; @@ -119,8 +122,7 @@ namespace BCDD public MatchCollection ValidateAbility(String ability) { - Regex abilityMatch = new Regex(@"\b([NESW]):([0-9A-D]{5})\b"); - MatchCollection matches = abilityMatch.Matches(ability); + MatchCollection matches = PBNBoard.abilityPattern.Matches(ability); if (matches.Count != 4) { this.hasAbility = false; @@ -210,12 +212,11 @@ namespace BCDD public List ValidateOptimumResultTable(List table) { - Regex linePattern = new Regex(@"^([NESW])\s+([CDHSN])T?\s+(\d+)$"); List matches = new List(); List duplicates = new List(); foreach (String line in table) { - Match match = linePattern.Match(line); + Match match = PBNBoard.optimumResultTablePattern.Match(line); if (!match.Success) { this.hasOptimumResultTable = false; -- cgit v1.2.3