Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Fixed double parsing for different cultures
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Oct 26, 2020
1 parent 9296a0e commit e3a65dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Extensions.Test/F95ZoneTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,17 @@ public void TestLoadGames()
Assert.Equal(AGame.AgeRatingAdult, game.GetAgeRating());
});
}

[Fact]
public void TestRatingParsing()
{
const string s1 = "4.50";
const string s2 = "4,50";

Assert.True(F95ZoneGame.TryParseRating(s1, out var d1));
Assert.False(F95ZoneGame.TryParseRating(s2, out _));

Assert.Equal(4.50, d1);
}
}
}
14 changes: 10 additions & 4 deletions F95ZoneMetadata/F95ZoneGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Extensions.Common;
Expand Down Expand Up @@ -167,10 +168,7 @@ public override async Task<AGame> LoadGame()
var sRating = ratingNode.GetValue("title");
if (!sRating.IsEmpty())
{
if (sRating.EndsWith("star(s)"))
sRating = sRating.Replace("star(s)", "").Trim();

if (double.TryParse(sRating, out var rating))
if (TryParseRating(sRating, out var rating))
{
Rating = rating;
AvailableFields.Add(MetadataField.CommunityScore);
Expand Down Expand Up @@ -347,6 +345,14 @@ public override async Task<AGame> LoadGame()
return this;
}

public static bool TryParseRating(string sRating, out double rating)
{
if (sRating.EndsWith("star(s)"))
sRating = sRating.Replace("star(s)", "").Trim();

return double.TryParse(sRating, NumberStyles.Float, CultureInfo.InvariantCulture, out rating);
}

public override List<string> GetGenres()
{
return Genres;
Expand Down

0 comments on commit e3a65dc

Please sign in to comment.