diff --git a/ThScoreFileConverter/Models/Th105/CardForDeckReplacer.cs b/ThScoreFileConverter/Models/Th105/CardForDeckReplacer.cs index 2c36bd5d..c548f67f 100644 --- a/ThScoreFileConverter/Models/Th105/CardForDeckReplacer.cs +++ b/ThScoreFileConverter/Models/Th105/CardForDeckReplacer.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using ThScoreFileConverter.Core.Models; using ThScoreFileConverter.Core.Models.Th105; using ThScoreFileConverter.Helpers; @@ -18,8 +19,9 @@ namespace ThScoreFileConverter.Models.Th105; // %T105DC[ww][x][yy][z] internal sealed class CardForDeckReplacer : IStringReplaceable { + private static readonly IntegerParser CardNumberParser = new(@"\d{2}"); private static readonly string Pattern = StringHelper.Create( - $@"{Definitions.FormatPrefix}DC({Parsers.CharaParser.Pattern})({Parsers.CardTypeParser.Pattern})(\d{{2}})([NC])"); + $@"{Definitions.FormatPrefix}DC({Parsers.CharaParser.Pattern})({Parsers.CardTypeParser.Pattern})({CardNumberParser.Pattern})([NC])"); private readonly MatchEvaluator evaluator; @@ -33,7 +35,7 @@ public CardForDeckReplacer( { var chara = Parsers.CharaParser.Parse(match.Groups[1].Value); var cardType = Parsers.CardTypeParser.Parse(match.Groups[2]); - var number = IntegerHelper.Parse(match.Groups[3].Value); + var number = CardNumberParser.Parse(match.Groups[3]); var type = match.Groups[4].Value.ToUpperInvariant(); ICardForDeck cardForDeck; diff --git a/ThScoreFileConverter/Models/Th105/CardReplacerBase.cs b/ThScoreFileConverter/Models/Th105/CardReplacerBase.cs index 8304ba55..1b08961c 100644 --- a/ThScoreFileConverter/Models/Th105/CardReplacerBase.cs +++ b/ThScoreFileConverter/Models/Th105/CardReplacerBase.cs @@ -36,11 +36,12 @@ protected CardReplacerBase( { var numLevels = EnumHelper.NumValues; var numDigits = IntegerHelper.GetNumDigits(enemyCardIdTable.Max(pair => pair.Value.Count()) * numLevels); + var cardNumberParser = new IntegerParser($@"\d{{{numDigits}}}"); - this.pattern = StringHelper.Create($@"{formatPrefix}CARD(\d{{{numDigits}}})({charaParser.Pattern})([NR])"); + this.pattern = StringHelper.Create($@"{formatPrefix}CARD({cardNumberParser.Pattern})({charaParser.Pattern})([NR])"); this.evaluator = new MatchEvaluator(match => { - var number = IntegerHelper.Parse(match.Groups[1].Value); + var number = cardNumberParser.Parse(match.Groups[1]); var chara = charaParser.Parse(match.Groups[2]); var type = match.Groups[3].Value.ToUpperInvariant(); diff --git a/ThScoreFileConverter/Models/Th105/CareerReplacerBase.cs b/ThScoreFileConverter/Models/Th105/CareerReplacerBase.cs index 1c1b4267..f4086541 100644 --- a/ThScoreFileConverter/Models/Th105/CareerReplacerBase.cs +++ b/ThScoreFileConverter/Models/Th105/CareerReplacerBase.cs @@ -22,6 +22,8 @@ namespace ThScoreFileConverter.Models.Th105; internal class CareerReplacerBase : IStringReplaceable where TChara : struct, Enum { + private static readonly IntegerParser TypeParser = new(@"[1-3]"); + private readonly string pattern; private readonly MatchEvaluator evaluator; @@ -35,13 +37,14 @@ protected CareerReplacerBase( { var numLevels = EnumHelper.NumValues; var numDigits = IntegerHelper.GetNumDigits(enemyCardIdTable.Max(pair => pair.Value.Count()) * numLevels); + var cardNumberParser = new IntegerParser($@"\d{{{numDigits}}}"); - this.pattern = StringHelper.Create($@"{formatPrefix}C(\d{{{numDigits}}})({charaParser.Pattern})([1-3])"); + this.pattern = StringHelper.Create($@"{formatPrefix}C({cardNumberParser.Pattern})({charaParser.Pattern})({TypeParser.Pattern})"); this.evaluator = new MatchEvaluator(match => { - var number = IntegerHelper.Parse(match.Groups[1].Value); + var number = cardNumberParser.Parse(match.Groups[1]); var chara = charaParser.Parse(match.Groups[2]); - var type = IntegerHelper.Parse(match.Groups[3].Value); + var type = TypeParser.Parse(match.Groups[3]); if (!canReplace(number, chara, type)) return match.ToString(); diff --git a/ThScoreFileConverter/Models/Th105/CollectRateReplacerBase.cs b/ThScoreFileConverter/Models/Th105/CollectRateReplacerBase.cs index b8d2bbe3..7c6f3e8f 100644 --- a/ThScoreFileConverter/Models/Th105/CollectRateReplacerBase.cs +++ b/ThScoreFileConverter/Models/Th105/CollectRateReplacerBase.cs @@ -22,6 +22,8 @@ namespace ThScoreFileConverter.Models.Th105; internal class CollectRateReplacerBase : IStringReplaceable where TChara : struct, Enum { + private static readonly IntegerParser TypeParser = new(@"[12]"); + private readonly string pattern; private readonly MatchEvaluator evaluator; @@ -34,12 +36,12 @@ protected CollectRateReplacerBase( INumberFormatter formatter) { this.pattern = StringHelper.Create( - $"{formatPrefix}CRG({levelWithTotalParser.Pattern})({charaParser.Pattern})([1-2])"); + $"{formatPrefix}CRG({levelWithTotalParser.Pattern})({charaParser.Pattern})({TypeParser.Pattern})"); this.evaluator = new MatchEvaluator(match => { var level = levelWithTotalParser.Parse(match.Groups[1]); var chara = charaParser.Parse(match.Groups[2]); - var type = IntegerHelper.Parse(match.Groups[3].Value); + var type = TypeParser.Parse(match.Groups[3]); if (!canReplace(level, chara, type)) return match.ToString();