diff --git a/src/LibreLancer.Data/Ini/LancerTextIniParser.cs b/src/LibreLancer.Data/Ini/LancerTextIniParser.cs index d8714b16..92d39ac7 100644 --- a/src/LibreLancer.Data/Ini/LancerTextIniParser.cs +++ b/src/LibreLancer.Data/Ini/LancerTextIniParser.cs @@ -12,13 +12,13 @@ namespace LibreLancer.Ini { /// - /// Implementation of a text ini parser which comes as close to the original as possible. + /// Implementation of a text ini parser which comes as close to the original as possible. /// /// /// Freelancer data contains a mixture of binary ini and text ini files. The text ini files /// seem to contain nbsp (0xa0) characters from the windows-1252 code page which can be seen in /// DATA/initialworld.ini. The means that unless the ini file has BOM we should interpret the - /// file data as from this code page. + /// file data as from this code page. /// public class LancerTextIniParser : IIniParser { @@ -70,8 +70,7 @@ private static void ParseKeyValue(Section section, string key, string value, int { entry.Add(new Int32Value((int)tempLong) { Entry = entry, Line = line }); } - else if (float.TryParse(part, NumberStyles.Float, CultureInfo.InvariantCulture, out float tempFloat) - && tempFloat.ToString() == Convert.ToDouble(part).ToString()) + else if (float.TryParse(part, NumberStyles.Float, CultureInfo.InvariantCulture, out float tempFloat)) { entry.Add(new SingleValue(tempFloat, null) { Entry = entry, Line = line }); } diff --git a/src/LibreLancer.Tests/Ini/LocaleTests.cs b/src/LibreLancer.Tests/Ini/LocaleTests.cs new file mode 100644 index 00000000..aa3f2513 --- /dev/null +++ b/src/LibreLancer.Tests/Ini/LocaleTests.cs @@ -0,0 +1,44 @@ +using System; +using System.Globalization; +using System.IO; +using System.Linq; +using LibreLancer.Ini; +using System.Text; +using FluentAssertions; +using Xunit; + +namespace LibreLancer.Tests.Ini; + +public class LocaleTests +{ + void RunWithLocale(string locale, Action action) + { + var currentLocale = CultureInfo.CurrentCulture; + var locale2 = CultureInfo.GetCultureInfo(locale); + CultureInfo.CurrentCulture = locale2; + action(); + CultureInfo.CurrentCulture = currentLocale; + } + + [Theory] + [InlineData("en-US")] + [InlineData("de-DE")] + [InlineData("es-ES")] + public void TestDecimalSeparator(string locale) + { + RunWithLocale(locale, () => + { + var parser = new LancerTextIniParser(); + var s = new MemoryStream("[Section]\nValue = 1.1"u8.ToArray()); + + var p = parser.ParseIniFile("[data]", s, true, false).ToArray(); + p.Should().HaveCount(1); + p[0].Name.Should().Be("Section"); + p[0].Should().HaveCount(1); + p[0][0].Name.Should().Be("Value"); + p[0][0].Should().HaveCount(1); + p[0][0][0].Should().BeOfType(); + p[0][0][0].ToSingle().Should().Be(1.1f); + }); + } +}