diff --git a/ThScoreFileConverter/Models/Th165/CardReplacer.cs b/ThScoreFileConverter/Models/Th165/CardReplacer.cs index 4ef6bf86..c69b1c08 100644 --- a/ThScoreFileConverter/Models/Th165/CardReplacer.cs +++ b/ThScoreFileConverter/Models/Th165/CardReplacer.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Text.RegularExpressions; using ThScoreFileConverter.Core.Extensions; +using ThScoreFileConverter.Core.Models; using ThScoreFileConverter.Helpers; namespace ThScoreFileConverter.Models.Th165; @@ -18,14 +19,15 @@ namespace ThScoreFileConverter.Models.Th165; // %T165CARD[xx][y][z] internal sealed class CardReplacer(IReadOnlyList scores, bool hideUntriedCards) : IStringReplaceable { + private static readonly IntegerParser TypeParser = new(@"[12]"); private static readonly string Pattern = StringHelper.Create( - $"{Definitions.FormatPrefix}CARD({Parsers.DayParser.Pattern})([1-7])([12])"); + $"{Definitions.FormatPrefix}CARD({Parsers.DayParser.Pattern})({Parsers.SceneParser.Pattern})({TypeParser.Pattern})"); private readonly MatchEvaluator evaluator = new(match => { var day = Parsers.DayParser.Parse(match.Groups[1]); - var scene = IntegerHelper.Parse(match.Groups[2].Value); - var type = IntegerHelper.Parse(match.Groups[3].Value); + var scene = Parsers.SceneParser.Parse(match.Groups[2]); + var type = TypeParser.Parse(match.Groups[3]); var key = (day, scene); if (!Definitions.SpellCards.TryGetValue(key, out var enemyCardPair)) diff --git a/ThScoreFileConverter/Models/Th165/NicknameReplacer.cs b/ThScoreFileConverter/Models/Th165/NicknameReplacer.cs index df243ff3..871df8ef 100644 --- a/ThScoreFileConverter/Models/Th165/NicknameReplacer.cs +++ b/ThScoreFileConverter/Models/Th165/NicknameReplacer.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text.RegularExpressions; +using ThScoreFileConverter.Core.Models; using ThScoreFileConverter.Helpers; namespace ThScoreFileConverter.Models.Th165; @@ -16,11 +17,12 @@ namespace ThScoreFileConverter.Models.Th165; // %T165NICK[xx] internal sealed class NicknameReplacer(IStatus status) : IStringReplaceable { - private static readonly string Pattern = StringHelper.Create($@"{Definitions.FormatPrefix}NICK(\d{{2}})"); + private static readonly IntegerParser NumberParser = new(@"\d{2}"); + private static readonly string Pattern = StringHelper.Create($@"{Definitions.FormatPrefix}NICK({NumberParser.Pattern})"); private readonly MatchEvaluator evaluator = new(match => { - var number = IntegerHelper.Parse(match.Groups[1].Value); + var number = NumberParser.Parse(match.Groups[1]); if ((number > 0) && (number <= Definitions.Nicknames.Count)) { diff --git a/ThScoreFileConverter/Models/Th165/Parsers.cs b/ThScoreFileConverter/Models/Th165/Parsers.cs index 4e23d7bd..bea128d1 100644 --- a/ThScoreFileConverter/Models/Th165/Parsers.cs +++ b/ThScoreFileConverter/Models/Th165/Parsers.cs @@ -18,4 +18,9 @@ internal static class Parsers /// Gets the parser of . /// public static Core.Models.EnumPatternParser DayParser { get; } = new(); + + /// + /// Gets the parser of scenes. + /// + public static Core.Models.IntegerParser SceneParser { get; } = new(@"[1-7]"); } diff --git a/ThScoreFileConverter/Models/Th165/ScoreReplacer.cs b/ThScoreFileConverter/Models/Th165/ScoreReplacer.cs index dff9470d..1644764c 100644 --- a/ThScoreFileConverter/Models/Th165/ScoreReplacer.cs +++ b/ThScoreFileConverter/Models/Th165/ScoreReplacer.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using ThScoreFileConverter.Core.Models; using ThScoreFileConverter.Helpers; namespace ThScoreFileConverter.Models.Th165; @@ -17,14 +18,15 @@ namespace ThScoreFileConverter.Models.Th165; // %T165SCR[xx][y][z] internal sealed class ScoreReplacer(IReadOnlyList scores, INumberFormatter formatter) : IStringReplaceable { + private static readonly IntegerParser TypeParser = new(@"[1-4]"); private static readonly string Pattern = StringHelper.Create( - $"{Definitions.FormatPrefix}SCR({Parsers.DayParser.Pattern})([1-7])([1-4])"); + $"{Definitions.FormatPrefix}SCR({Parsers.DayParser.Pattern})({Parsers.SceneParser.Pattern})({TypeParser.Pattern})"); private readonly MatchEvaluator evaluator = new(match => { var day = Parsers.DayParser.Parse(match.Groups[1]); - var scene = IntegerHelper.Parse(match.Groups[2].Value); - var type = IntegerHelper.Parse(match.Groups[3].Value); + var scene = Parsers.SceneParser.Parse(match.Groups[2]); + var type = TypeParser.Parse(match.Groups[3]); var key = (day, scene); if (!Definitions.SpellCards.ContainsKey(key)) diff --git a/ThScoreFileConverter/Models/Th165/ScoreTotalReplacer.cs b/ThScoreFileConverter/Models/Th165/ScoreTotalReplacer.cs index 01c60d1f..8e0411f1 100644 --- a/ThScoreFileConverter/Models/Th165/ScoreTotalReplacer.cs +++ b/ThScoreFileConverter/Models/Th165/ScoreTotalReplacer.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using ThScoreFileConverter.Core.Models; using ThScoreFileConverter.Helpers; namespace ThScoreFileConverter.Models.Th165; @@ -18,11 +19,12 @@ namespace ThScoreFileConverter.Models.Th165; internal sealed class ScoreTotalReplacer(IReadOnlyList scores, IStatus status, INumberFormatter formatter) : IStringReplaceable { - private static readonly string Pattern = StringHelper.Create($"{Definitions.FormatPrefix}SCRTL([1-6])"); + private static readonly IntegerParser TypeParser = new(@"[1-6]"); + private static readonly string Pattern = StringHelper.Create($"{Definitions.FormatPrefix}SCRTL({TypeParser.Pattern})"); private readonly MatchEvaluator evaluator = new(match => { - var type = IntegerHelper.Parse(match.Groups[1].Value); + var type = TypeParser.Parse(match.Groups[1]); return type switch { diff --git a/ThScoreFileConverter/Models/Th165/ShotExReplacer.cs b/ThScoreFileConverter/Models/Th165/ShotExReplacer.cs index ef23a03f..d4279d1f 100644 --- a/ThScoreFileConverter/Models/Th165/ShotExReplacer.cs +++ b/ThScoreFileConverter/Models/Th165/ShotExReplacer.cs @@ -12,6 +12,7 @@ using System.Globalization; using System.Linq; using System.Text.RegularExpressions; +using ThScoreFileConverter.Core.Models; using ThScoreFileConverter.Core.Models.Th165; using ThScoreFileConverter.Helpers; @@ -24,8 +25,9 @@ internal sealed class ShotExReplacer( string outputFilePath) : IStringReplaceable { + private static readonly IntegerParser TypeParser = new(@"[1-9]"); private static readonly string Pattern = StringHelper.Create( - $"{Definitions.FormatPrefix}SHOTEX({Parsers.DayParser.Pattern})([1-7])([1-9])"); + $"{Definitions.FormatPrefix}SHOTEX({Parsers.DayParser.Pattern})({Parsers.SceneParser.Pattern})({TypeParser.Pattern})"); private static readonly Func> HashtagList = header => @@ -96,8 +98,8 @@ internal sealed class ShotExReplacer( private readonly MatchEvaluator evaluator = new(match => { var day = Parsers.DayParser.Parse(match.Groups[1]); - var scene = IntegerHelper.Parse(match.Groups[2].Value); - var type = IntegerHelper.Parse(match.Groups[3].Value); + var scene = Parsers.SceneParser.Parse(match.Groups[2]); + var type = TypeParser.Parse(match.Groups[3]); var key = (day, scene); if (!Definitions.SpellCards.ContainsKey(key)) diff --git a/ThScoreFileConverter/Models/Th165/ShotReplacer.cs b/ThScoreFileConverter/Models/Th165/ShotReplacer.cs index 09fa3284..04809535 100644 --- a/ThScoreFileConverter/Models/Th165/ShotReplacer.cs +++ b/ThScoreFileConverter/Models/Th165/ShotReplacer.cs @@ -20,12 +20,12 @@ internal sealed class ShotReplacer( : IStringReplaceable { private static readonly string Pattern = StringHelper.Create( - $"{Definitions.FormatPrefix}SHOT({Parsers.DayParser.Pattern})([1-7])"); + $"{Definitions.FormatPrefix}SHOT({Parsers.DayParser.Pattern})({Parsers.SceneParser.Pattern})"); private readonly MatchEvaluator evaluator = new(match => { var day = Parsers.DayParser.Parse(match.Groups[1]); - var scene = IntegerHelper.Parse(match.Groups[2].Value); + var scene = Parsers.SceneParser.Parse(match.Groups[2]); var key = (day, scene); if (!Definitions.SpellCards.TryGetValue(key, out var enemyCardPair))