From abde8aa4448c6b0b12a3573674f836a9d0a4603c Mon Sep 17 00:00:00 2001 From: Carlo Barazzetta Date: Wed, 2 Dec 2020 10:26:57 +0100 Subject: [PATCH] Removed IsFloat function --- Svg/SVGColor.pas | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/Svg/SVGColor.pas b/Svg/SVGColor.pas index c563a55b..93587e4a 100644 --- a/Svg/SVGColor.pas +++ b/Svg/SVGColor.pas @@ -87,21 +87,11 @@ function IsDecimal(const S: string): Boolean; Result := True; end; -function IsFloat(const S: string): Boolean; -var - C: Integer; -begin - Result := False; - for C := 1 to Length(S) do - if not (((S[C] >= '0') and (S[C] <= '9')) or (S[C] = '.')) then - Exit; - Result := True; -end; - function DecodeSVGColorToInt(const S: string): Integer; var C: Integer; Percent: Boolean; + ColorFloat: Extended; Help: string; LFormatSettings: TFormatSettings; begin @@ -126,13 +116,16 @@ function DecodeSVGColorToInt(const S: string): Integer; if Percent then C := Round(C * 2.55); end - else if IsFloat(Help) then + else begin LFormatSettings.DecimalSeparator := '.'; - if Percent then - C := Round(StrToFloat(Help, LFormatSettings)*2.55) - else - C := Round(StrToFloat(Help, LFormatSettings)); + If TryStrToFloat(Help, ColorFloat, LFormatSettings) then + begin + if Percent then + C := Round(ColorFloat * 2.55) + else + C := Round(ColorFloat); + end; end; if C = SVG_INHERIT_COLOR then Exit;