Skip to content

Commit

Permalink
Fix to use IntegerParser for th17.5
Browse files Browse the repository at this point in the history
  • Loading branch information
y-iihoshi committed Jan 1, 2025
1 parent 284cdda commit 8ed5c66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions ThScoreFileConverter/Models/Th175/CharaReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 =>
{
Expand All @@ -37,7 +39,7 @@ static int GetCount(IReadOnlyDictionary<Chara, int> 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
{
Expand Down
8 changes: 5 additions & 3 deletions ThScoreFileConverter/Models/Th175/ScoreReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
{
Expand All @@ -35,8 +37,8 @@ static IEnumerable<int> 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
{
Expand Down

0 comments on commit 8ed5c66

Please sign in to comment.