From 8ed5c6668c3890aa2ba68e381f89f8cd056ea057 Mon Sep 17 00:00:00 2001 From: IIHOSHI Yoshinori Date: Thu, 2 Jan 2025 06:36:33 +0900 Subject: [PATCH] Fix to use IntegerParser for th17.5 --- ThScoreFileConverter/Models/Th175/CharaReplacer.cs | 6 ++++-- ThScoreFileConverter/Models/Th175/ScoreReplacer.cs | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ThScoreFileConverter/Models/Th175/CharaReplacer.cs b/ThScoreFileConverter/Models/Th175/CharaReplacer.cs index 8c3a6cc3..f889408c 100644 --- a/ThScoreFileConverter/Models/Th175/CharaReplacer.cs +++ b/ThScoreFileConverter/Models/Th175/CharaReplacer.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using ThScoreFileConverter.Core.Models; using ThScoreFileConverter.Core.Models.Th175; using ThScoreFileConverter.Helpers; @@ -24,8 +25,9 @@ internal sealed class CharaReplacer( INumberFormatter formatter) : IStringReplaceable { + private static readonly IntegerParser TypeParser = new(@"[1-4]"); private static readonly string Pattern = StringHelper.Create( - $"{Definitions.FormatPrefix}CHR({Parsers.CharaWithTotalParser.Pattern})([1-4])"); + $"{Definitions.FormatPrefix}CHR({Parsers.CharaWithTotalParser.Pattern})({TypeParser.Pattern})"); private readonly MatchEvaluator evaluator = new(match => { @@ -37,7 +39,7 @@ static int GetCount(IReadOnlyDictionary dictionary, CharaWithTotal c } var chara = Parsers.CharaWithTotalParser.Parse(match.Groups[1].Value); - var type = IntegerHelper.Parse(match.Groups[2].Value); + var type = TypeParser.Parse(match.Groups[2]); return type switch { diff --git a/ThScoreFileConverter/Models/Th175/ScoreReplacer.cs b/ThScoreFileConverter/Models/Th175/ScoreReplacer.cs index 299eae1e..46a10f00 100644 --- a/ThScoreFileConverter/Models/Th175/ScoreReplacer.cs +++ b/ThScoreFileConverter/Models/Th175/ScoreReplacer.cs @@ -22,8 +22,10 @@ internal sealed class ScoreReplacer( INumberFormatter formatter) : IStringReplaceable { + private static readonly Core.Models.IntegerParser RankParser = new(@"\d"); + private static readonly Core.Models.IntegerParser TypeParser = new(@"[12]"); private static readonly string Pattern = StringHelper.Create( - $@"{Definitions.FormatPrefix}SCR({Parsers.LevelParser.Pattern})({Parsers.CharaParser.Pattern})(\d)([12])"); + $@"{Definitions.FormatPrefix}SCR({Parsers.LevelParser.Pattern})({Parsers.CharaParser.Pattern})({RankParser.Pattern})({TypeParser.Pattern})"); private readonly MatchEvaluator evaluator = new(match => { @@ -35,8 +37,8 @@ static IEnumerable GetRanking( var level = Parsers.LevelParser.Parse(match.Groups[1]); var chara = Parsers.CharaParser.Parse(match.Groups[2].Value); - var rank = IntegerHelper.ToZeroBased(IntegerHelper.Parse(match.Groups[3].Value)); - var type = IntegerHelper.Parse(match.Groups[4].Value); + var rank = IntegerHelper.ToZeroBased(RankParser.Parse(match.Groups[3])); + var type = TypeParser.Parse(match.Groups[4]); return type switch {