fpTOML icon indicating copy to clipboard operation
fpTOML copied to clipboard

Float number and date parsing may fail in different countries

Open nussbaumer-planb opened this issue 1 year ago • 1 comments

Problem: The float number and date parsing may fail in other countries, that is: where a system locale is set that is not English. The reason for that is that you use the StrToFloat variant without the TFormatSettings parameter (two locations in TOMLParser.pas). This variant uses the system locale which may or may not match the TOML specification.

Solution: change these two code locations to use the StrToFloat variant that takes a second parameter of type TFormatSettings and specify settings that you created explicitly, e.g. by calling TFormatSettings.Create('en-US').

nussbaumer-planb avatar Jul 05 '24 09:07 nussbaumer-planb

The simplest and most effective solution:

TToken.RealNumber:
begin
    SScanf(pattern, '%f', [@f]);
    result := TTOMLNumber.Create(f, TTOMLNumberType.Float);
    Consume;
end;

Perchik71 avatar Jun 20 '25 17:06 Perchik71