Skip to content

Commit

Permalink
Enforce float parse style + throw VDFSyntaxException
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolbros committed Feb 15, 2024
1 parent f9b8e38 commit cffa278
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/HUDAnimations/HUDAnimationsSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using HUDAnimations.Models;
using HUDAnimations.Models.Animations;
using HUDAnimations.Models.Interpolators;
Expand Down Expand Up @@ -119,26 +119,43 @@ string ReadString()

float ReadNumber()
{
string value = ReadString();

// Support floats with multiple decimals e.g. "0.1.5"
string value = "";
string result = "";

bool seen = false;
foreach (char c in ReadString())

foreach (char c in value)
{
if (c == '.')
{
if (!seen)
{
value += c;
result += c;
seen = true;
}
}
else
{
value += c;
result += c;
}
}

return float.Parse(value);
try
{
return float.Parse(result, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
}
catch (FormatException)
{
throw new VDFSyntaxException(
new VDFToken { Type = VDFTokenType.String, Value = value },
["number"],
tokeniser.Index,
tokeniser.Line,
tokeniser.Character
);
}
}

bool ReadBool()
Expand Down

0 comments on commit cffa278

Please sign in to comment.